Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
d190860e
Commit
d190860e
authored
Aug 24, 2016
by
Victor Yacovlev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qt5 headless initialization fix
parent
6bf8ba8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
63 deletions
+76
-63
scripts/gen_actor_source.py
scripts/gen_actor_source.py
+3
-3
src/app/main.cpp
src/app/main.cpp
+73
-60
No files found.
scripts/gen_actor_source.py
View file @
d190860e
...
...
@@ -1166,7 +1166,7 @@ class Settings:
result
+=
entry
.
get_entry_cpp_implementation
(
"entries"
)
result
+=
"""
bool guiAvailable = true;
#ifdef Q_
WS_X11
#ifdef Q_
OS_LINUX
guiAvailable = 0 != getenv("DISPLAY");
#endif
if (guiAvailable) {
...
...
@@ -2656,7 +2656,7 @@ class ModuleBaseCppClass(CppClassBase):
: QObject(parent)
{
bool hasGui = true;
#ifdef Q_
WS_X11
#ifdef Q_
OS_LINUX
hasGui = getenv("DISPLAY")!=0;
#endif
if (hasGui) {
...
...
@@ -2739,7 +2739,7 @@ class ModuleBaseCppClass(CppClassBase):
/* public */ QList<QMenu*> %s::moduleMenus() const
{
bool hasGui = true;
#ifdef Q_
WS_X11
#ifdef Q_
OS_LINUX
hasGui = getenv("DISPLAY")!=0;
#endif
if (hasGui) {
...
...
src/app/main.cpp
View file @
d190860e
...
...
@@ -83,23 +83,31 @@ QString getLanguage()
}
class
Application
:
public
QApplication
class
Application
:
QObject
{
public:
inline
explicit
Application
(
int
&
argc
,
char
**
argv
,
bool
gui
)
:
QApplication
(
argc
,
argv
,
gui
)
,
timerId_
(
-
1
)
,
splashScreen_
(
nullptr
)
,
started_
(
false
)
{}
:
QObject
()
,
_qApp
(
0
)
,
_timerId
(
-
1
)
,
_splashScreen
(
nullptr
)
,
_started
(
false
)
{
if
(
gui
)
{
_qApp
=
new
QApplication
(
argc
,
argv
);
}
else
{
_qApp
=
new
QCoreApplication
(
argc
,
argv
);
}
_qApp
->
installEventFilter
(
this
);
}
inline
void
setSplashScreen
(
QSplashScreen
*
s
)
{
splashScreen_
=
s
;
_splashScreen
=
s
;
}
inline
void
initialize
()
{
const
QStringList
arguments
=
QCoreApplication
::
instance
()
->
arguments
();
const
QStringList
arguments
=
_qApp
->
arguments
();
qDebug
()
<<
"Arguments: "
<<
arguments
;
bool
mustShowHelpAndExit
=
false
;
bool
mustShowVersionAndExit
=
false
;
...
...
@@ -119,24 +127,24 @@ public:
}
bool
gui
=
true
;
#ifdef Q_
WS_X11
#ifdef Q_
OS_LINUX
gui
=
gui
&&
getenv
(
"DISPLAY"
)
!=
0
;
#endif
const
QString
sharePath
=
QDir
(
applicationDirPath
()
+
SHARE_PATH
).
canonicalPath
();
const
QString
sharePath
=
QDir
(
_qApp
->
applicationDirPath
()
+
SHARE_PATH
).
canonicalPath
();
QDir
translationsDir
(
sharePath
+
"/translations"
);
QStringList
ts_files
=
translationsDir
.
entryList
(
QStringList
()
<<
"*_"
+
getLanguage
()
+
".qm"
);
foreach
(
QString
tsname
,
ts_files
)
{
tsname
=
tsname
.
mid
(
0
,
tsname
.
length
()
-
3
);
QTranslator
*
tr
=
new
QTranslator
(
this
);
QTranslator
*
tr
=
new
QTranslator
(
_qApp
);
if
(
tr
->
load
(
tsname
,
sharePath
+
"/translations"
))
{
installTranslator
(
tr
);
_qApp
->
installTranslator
(
tr
);
}
}
qDebug
()
<<
"Loaded translator files"
;
setProperty
(
"sharePath"
,
sharePath
);
_qApp
->
setProperty
(
"sharePath"
,
sharePath
);
QSettings
::
setDefaultFormat
(
QSettings
::
IniFormat
);
addLibraryPath
(
PLUGINS_PATH
);
_qApp
->
addLibraryPath
(
PLUGINS_PATH
);
ExtensionSystem
::
PluginManager
*
manager
=
ExtensionSystem
::
PluginManager
::
instance
();
manager
->
setPluginPath
(
PLUGINS_PATH
);
manager
->
setSharePath
(
sharePath
);
...
...
@@ -157,10 +165,10 @@ public:
qDebug
()
<<
"Loading plugins by template: "
<<
templ
;
error
=
manager
->
loadPluginsByTemplate
(
templ
);
if
(
!
gui
&&
manager
->
isGuiRequired
())
{
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
showErrorMessage
(
"Requires X11 session to run this configuration"
);
exit
(
1
);
_qApp
->
exit
(
1
);
}
// qInstallMsgHandler(manager->isGuiRequired()
...
...
@@ -168,17 +176,17 @@ public:
// : ConsoleMessageOutput);
if
(
!
error
.
isEmpty
())
{
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
showErrorMessage
(
error
);
exit
(
1
);
_qApp
->
exit
(
1
);
}
qDebug
()
<<
"Done loading all plugins by template"
;
if
(
mustShowHelpAndExit
)
{
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
const
QString
msg
=
manager
->
commandLineHelp
();
#ifdef Q_OS_WIN32
QTextCodec
*
codec
=
QTextCodec
::
codecForName
(
"CP866"
);
...
...
@@ -186,65 +194,68 @@ public:
#else
fprintf
(
stderr
,
"%s"
,
msg
.
toLocal8Bit
().
data
());
#endif
exit
(
0
);
_qApp
->
exit
(
0
);
return
;
}
if
(
mustShowVersionAndExit
)
{
fprintf
(
stderr
,
"%s
\n
"
,
qPrintable
(
applicationVersion
()));
exit
(
0
);
fprintf
(
stderr
,
"%s
\n
"
,
qPrintable
(
_qApp
->
applicationVersion
()));
_qApp
->
exit
(
0
);
return
;
}
qDebug
()
<<
"Begin plugins initialization"
;
error
=
manager
->
initializePlugins
();
if
(
!
error
.
isEmpty
())
{
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
showErrorMessage
(
error
);
exit
(
property
(
"returnCode"
).
isValid
()
?
property
(
"returnCode"
).
toInt
()
:
1
);
_qApp
->
exit
(
_qApp
->
property
(
"returnCode"
).
isValid
()
?
_qApp
->
property
(
"returnCode"
).
toInt
()
:
1
);
}
// GUI requirement may be changed as result of plugins initialization,
// so check it again
qDebug
()
<<
"Plugins initialization done"
;
if
(
!
gui
&&
manager
->
isGuiRequired
())
{
showErrorMessage
(
"Requires X11 session to run this configuration"
);
exit
(
property
(
"returnCode"
).
isValid
()
?
property
(
"returnCode"
).
toInt
()
:
1
);
_qApp
->
exit
(
_qApp
->
property
(
"returnCode"
).
isValid
()
?
_qApp
->
property
(
"returnCode"
).
toInt
()
:
1
);
}
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
qDebug
()
<<
"Starting entry point plugin"
;
error
=
manager
->
start
();
if
(
!
error
.
isEmpty
())
{
if
(
splashScreen_
)
splashScreen_
->
finish
(
0
);
if
(
_splashScreen
)
_splashScreen
->
finish
(
0
);
showErrorMessage
(
error
);
exit
(
property
(
"returnCode"
).
isValid
()
?
property
(
"returnCode"
).
toInt
()
:
1
);
_qApp
->
exit
(
_qApp
->
property
(
"returnCode"
).
isValid
()
?
_qApp
->
property
(
"returnCode"
).
toInt
()
:
1
);
}
if
(
!
manager
->
isGuiRequired
())
{
quit
();
_qApp
->
quit
();
}
}
inline
void
timerEvent
(
QTimerEvent
*
event
)
{
if
(
!
started_
)
{
started_
=
true
;
killTimer
(
timerId_
);
inline
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
{
if
(
event
->
type
()
==
QEvent
::
Timer
&&
obj
==
_qApp
&&
!
_started
)
{
_started
=
true
;
_qApp
->
killTimer
(
_timerId
);
qDebug
()
<<
"Begin initialization"
;
initialize
();
qDebug
()
<<
"Initialization done"
;
return
true
;
}
else
{
return
QObject
::
eventFilter
(
obj
,
event
);
}
event
->
accept
();
}
inline
int
main
()
{
timerId_
=
startTimer
(
250
);
int
ret
=
exec
();
inline
int
main
()
{
_timerId
=
_qApp
->
startTimer
(
250
);
int
ret
=
_qApp
->
exec
();
if
(
ret
==
0
)
{
return
property
(
"returnCode"
).
isValid
()
?
property
(
"returnCode"
).
toInt
()
:
0
;
return
_qApp
->
property
(
"returnCode"
).
isValid
()
?
_qApp
->
property
(
"returnCode"
).
toInt
()
:
0
;
}
else
{
return
ret
;
...
...
@@ -252,9 +263,11 @@ public:
}
private:
int
timerId_
;
QSplashScreen
*
splashScreen_
;
bool
started_
;
QCoreApplication
*
_qApp
;
int
_timerId
;
QSplashScreen
*
_splashScreen
;
bool
_started
;
};
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -271,25 +284,25 @@ int main(int argc, char **argv)
bool
gui
=
true
;
#ifdef Q_
WS_X11
#ifdef Q_
OS_LINUX
gui
=
gui
&&
getenv
(
"DISPLAY"
)
!=
0
;
#endif
Application
*
app
=
new
Application
(
argc
,
argv
,
gui
);
QLocale
russian
=
QLocale
(
"ru_RU"
);
QLocale
::
setDefault
(
russian
);
#ifdef Q_OS_WIN32
app
->
addLibraryPath
(
a
pp
->
applicationDirPath
());
qApp
->
addLibraryPath
(
qA
pp
->
applicationDirPath
());
#endif
#ifndef Q_OS_WIN32
app
->
addLibraryPath
(
QDir
::
cleanPath
(
a
pp
->
applicationDirPath
()
+
"/../"
+
IDE_LIBRARY_BASENAME
+
"/kumir2/"
));
qApp
->
addLibraryPath
(
QDir
::
cleanPath
(
qA
pp
->
applicationDirPath
()
+
"/../"
+
IDE_LIBRARY_BASENAME
+
"/kumir2/"
));
#endif
a
pp
->
setApplicationVersion
(
gitTag
.
length
()
>
0
&&
gitTag
!=
"unknown"
qA
pp
->
setApplicationVersion
(
gitTag
.
length
()
>
0
&&
gitTag
!=
"unknown"
?
gitTag
:
gitBranch
+
"/"
+
gitHash
);
a
pp
->
setProperty
(
"gitTimeStamp"
,
gitTimeStamp
);
qA
pp
->
setProperty
(
"gitTimeStamp"
,
gitTimeStamp
);
QSplashScreen
*
splashScreen
=
0
;
const
QString
sharePath
=
QDir
(
a
pp
->
applicationDirPath
()
+
SHARE_PATH
).
canonicalPath
();
const
QString
sharePath
=
QDir
(
qA
pp
->
applicationDirPath
()
+
SHARE_PATH
).
canonicalPath
();
const
QStringList
arguments
=
QCoreApplication
::
instance
()
->
arguments
();
bool
mustShowHelpAndExit
=
false
;
...
...
@@ -322,8 +335,8 @@ int main(int argc, char **argv)
f
.
setPixelSize
(
12
);
p
.
setFont
(
f
);
QString
v
=
qApp
->
applicationVersion
();
if
(
a
pp
->
property
(
"gitHash"
).
isValid
())
{
v
+=
" (GIT "
+
a
pp
->
property
(
"gitHash"
).
toString
()
+
")"
;
if
(
qA
pp
->
property
(
"gitHash"
).
isValid
())
{
v
+=
" (GIT "
+
qA
pp
->
property
(
"gitHash"
).
toString
()
+
")"
;
}
int
tw
=
QFontMetrics
(
f
).
width
(
v
);
int
th
=
QFontMetrics
(
f
).
height
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment