Results 1 to 2 of 2

Thread: QCoreApplication in not-Qt GUI

  1. #1
    Join Date
    Jun 2020
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default 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
    Qt Code:
    1. QApplication was not created in main() thread
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. QApplication was not created in main() thread
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. Client * client = nullptr;
    2. std::thread th
    3. (
    4. [&]
    5. {
    6. QCoreApplication app(argc, argv);
    7. client = new Client;
    8. return app.exec();
    9. }
    10. );
    11.  
    12. th.detach();
    13. while(!client)
    14. {
    15. qDebug() << "nulptr";
    16. QThread::usleep(1000);
    17. }
    18. client->setHostName("localhost");
    To copy to clipboard, switch view to plain text mode 


    and see
    Qt Code:
    1. WARNING: QApplication was not created in the main() thread.
    2. nulptr
    3. nulptr
    4. nulptr
    5. QObject: Cannot create children for a parent that is in a different thread.
    6. (Parent is QSslSocket(0x7f4da80080c0), parent's thread is QThread(0x7f4da8000c60), current thread is QThread(0x56367f1e3ab0)
    To copy to clipboard, switch view to plain text mode 
    Last edited by CPPProger; 15th June 2020 at 16:00.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QCoreApplication in not-Qt GUI

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    CPPProger (15th June 2020)

Similar Threads

  1. QLocalServer without QCoreApplication ?
    By Raistlin in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2008, 23:44
  2. QCoreApplication::postEvent();
    By chrisdsimpson in forum Newbie
    Replies: 6
    Last Post: 1st April 2008, 22:23
  3. QCoreApplication
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 4th June 2007, 20:58
  4. Use of QCoreApplication
    By moowy in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 09:33
  5. QCoreApplication!!!!
    By fellobo in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2007, 01:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.