Re: QCoreApplication in not-Qt GUI
Friends, I'm yellow beginner in Qt. Tell me, please, is it possible to use QCoreApplication inside a non-GUI thread. I need to make the difficult asynchronous computing part of the application in C ++ (i use from Qt signals and slots, and sockets) and build a dynamic library. Then connect it to the JavaFX GUI application.
Can i to run Qt-code with QCoreApplication in non-main C ++ stream (std :: thread) or not? I see warning
and it's alarming me.
Maybe there is an example of this kind of use of Qt: calculation in C ++ Qt and use it as a dynamic library in Java GUI?
Added after 4 minutes:
Friends, I'm yellow beginner in Qt. Tell me, please, is it possible to use QCoreApplication inside a non-GUI thread. I need to make the difficult asynchronous computing part of the application in C ++ (i use from Qt signals and slots, and sockets) and build a dynamic library. Then connect it to the JavaFX GUI application.
Can i to run Qt-code with QCoreApplication in non-main C ++ stream (std :: thread) or not? I see warning
and it's alarming me.
Maybe there is an example of this kind of use of Qt: calculation in C ++ Qt and use it as a dynamic library in Java GUI?
Added after 45 minutes:
I try
Code:
Client * client = nullptr;
std::thread th
(
[&]
{
client = new Client;
return app.exec();
}
);
th.detach();
while(!client)
{
qDebug() << "nulptr";
}
client->setHostName("localhost");
and see
Code:
nulptr
nulptr
nulptr
QObject: Cannot create children
for a parent that is in a different thread.
(Parent is QSslSocket(0x7f4da80080c0), parent's thread is QThread(0x7f4da8000c60), current thread is QThread(0x56367f1e3ab0)
Re: QCoreApplication in not-Qt GUI
Quote:
WARNING: QApplication was not created in the main() thread.
As the message says, you cannot create a QCoreApplication instance anywhere except in the main thread of a program. The program's main Qt event loop must run in the main thread. So you can't implement a DLL with a stand-alone Qt event loop unless you can implement the QCoreApplication in the main thread. And if you are able to do that, then all other Qt objects which are children of QCoreApplication or another QObject-based class that is created in the main thread must also be created in the main thread.