Skip to content

Commit

Permalink
[skip ci] improve possibility to create a QApplication in a thread
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jun 20, 2020
1 parent 002e25b commit daec778
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/App/Application.cpp
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/Base/Console.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Main/FreeCADGuiPy.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit daec778

Please sign in to comment.