How to avoid Qt app.exec() blocking main thread

前端 未结 2 436
情深已故
情深已故 2020-11-29 05:58

I\'m new to Qt, but need to solve a difficult problem.

I\'ve created a VERY simple GUI that I need to add to an existing C++ application. The problem is, I\'m writin

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 06:48

    A good solution is found in: git@github.com:midjji/convenient_multithreaded_qt_gui.git

    then it's just e.g.

    run_in_gui_thread(new RunEventImpl([](){
            QMainWindow* window=new QMainWindow();
            window->show();
        }));
    

    callable from any thread, at any time, while taking care of setting things up for you in the bg.

    Note, this also takes care of creating a QApplication and executing it in a thread. But also works if you have already done so somewhere already.

提交回复
热议问题