[skip ci] improve possibility to create a QApplication in a thread
This commit is contained in:
@@ -1889,7 +1889,7 @@ void Application::initConfig(int argc, char ** argv)
|
||||
Branding brand;
|
||||
QString binDir = QString::fromUtf8((mConfig["AppHomePath"] + "bin").c_str());
|
||||
QFileInfo fi(binDir, QString::fromLatin1("branding.xml"));
|
||||
if (brand.readFile(fi.absoluteFilePath())) {
|
||||
if (fi.exists() && brand.readFile(fi.absoluteFilePath())) {
|
||||
Branding::XmlConfig cfg = brand.getUserDefines();
|
||||
for (Branding::XmlConfig::iterator it = cfg.begin(); it != cfg.end(); ++it) {
|
||||
App::Application::Config()[it.key()] = it.value();
|
||||
|
||||
@@ -126,8 +126,6 @@ ConsoleSingleton::ConsoleSingleton(void)
|
||||
,_defaultLogLevel(FC_LOGLEVEL_MSG)
|
||||
#endif
|
||||
{
|
||||
// make sure this object is part of the main thread
|
||||
ConsoleOutput::getInstance();
|
||||
}
|
||||
|
||||
ConsoleSingleton::~ConsoleSingleton()
|
||||
@@ -233,6 +231,11 @@ bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType
|
||||
void ConsoleSingleton::SetConnectionMode(ConnectionMode mode)
|
||||
{
|
||||
connectionMode = mode;
|
||||
|
||||
// make sure this method gets called from the main thread
|
||||
if (connectionMode == Queued) {
|
||||
ConsoleOutput::getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints a Message
|
||||
|
||||
@@ -109,6 +109,9 @@ FreeCADGui_showMainWindow(PyObject * /*self*/, PyObject *args)
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
#endif
|
||||
// This only works well if the QApplication is the very first created instance
|
||||
// of a QObject. Otherwise the application lives in a different thread than the
|
||||
// main thread which will cause hazardous behaviour.
|
||||
QtApplication app(argc, argv);
|
||||
if (setupMainWindow()) {
|
||||
app.exec();
|
||||
|
||||
Reference in New Issue
Block a user