Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QEventLoop: Cannot be used without QApplication Qt static
Forum Updated to NodeBB v4.3 + New Features

QEventLoop: Cannot be used without QApplication Qt static

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 6 Posters 11.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VRonin
    wrote on 24 Dec 2018, 08:13 last edited by
    #4

    Where's the event loop started in the code above? inside loggingFunction()?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    1
    • M Offline
      M Offline
      Mohammedbie
      wrote on 24 Dec 2018, 08:24 last edited by
      #5

      @VRonin

      loggingFunction() doesn't have an event loop it is a simple two lines code to initialize the logger of the program.

      I put QCoreApplication first and it doesn't change the output of the program.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 24 Dec 2018, 08:30 last edited by
        #6

        Do you have any global object? It's difficult to tell you what the problem is without code and without knowing how deep in the chain the snipped you posted is

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • M Offline
          M Offline
          Mohammedbie
          wrote on 24 Dec 2018, 08:39 last edited by Mohammedbie
          #7

          @VRonin
          Yes I have a single global variable but used only in main function and ProgramExecutable() function and what i posted is the main function of the tester.
          I followed the source of the error inside SignalR client code to a call to get function for a webpage.

          A 1 Reply Last reply 24 Dec 2018, 09:57
          0
          • M Offline
            M Offline
            Mohammedbie
            wrote on 24 Dec 2018, 08:54 last edited by
            #8

            What puzzles me what the difference between the static build and dynamic that could cause this ?

            1 Reply Last reply
            0
            • M Mohammedbie
              24 Dec 2018, 08:39

              @VRonin
              Yes I have a single global variable but used only in main function and ProgramExecutable() function and what i posted is the main function of the tester.
              I followed the source of the error inside SignalR client code to a call to get function for a webpage.

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 24 Dec 2018, 09:57 last edited by
              #9

              @Mohammedbie can you show the global variable? which type is it?

              Qt has to stay free or it will die.

              K 1 Reply Last reply 24 Dec 2018, 23:54
              4
              • D Offline
                D Offline
                dheerendra
                Qt Champions 2022
                wrote on 24 Dec 2018, 18:04 last edited by dheerendra
                #10

                There is not difference between the static and dynamic build. It could be the way you have written something. It could be the way you have defined the global variables somewhere. Some where you are creating some Qt objects globally without creating the QApplication object.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                1
                • A aha_1980
                  24 Dec 2018, 09:57

                  @Mohammedbie can you show the global variable? which type is it?

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 24 Dec 2018, 23:54 last edited by kshegunov
                  #11

                  I'm almost ready to bet that a QThread was created at global scope ... [1]

                  [1] https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qeventloop.cpp.html#_ZN10QEventLoopC1EP7QObject

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • M Offline
                    M Offline
                    Mohammedbie
                    wrote on 25 Dec 2018, 06:39 last edited by
                    #12

                    @aha_1980
                    it is a custom made class which have all the SDK operation I can't show it it all but here how it looks like :

                    class Program : public QObject
                    {
                    
                        Q_OBJECT
                    
                    public:
                        Program(QCoreApplication &app , int instance);
                        void Operation1();
                        void Operation2();
                    	void Operation3();
                    	void Operation4();
                        void Operation5();
                        void Operation6();
                        CustomClass2* Operation7();
                        void Operation8();
                    
                        CustomClass2* CustomInstance;
                        CustomClass3* CustomInstance2;
                        CustomClass4* CustomInstance3;
                        CustomClass5* CustomInstance4;
                        const char *pin = "1234";
                    
                    	static QHash<QString, QString> prop;
                    
                    private:
                        QVector<QUuid> *OpenSessions = new QVector<QUuid>();
                    	CustomClass4*a;
                    	QSslCertificate * cert;
                    	QSslKey * key;
                    	QList<QSslCertificate> * importedCerts;
                    	
                    
                    public slots:
                        void Slot1(arg args);
                    	void Slot2(arg *args);
                    	void Slot3(arg  *args);
                    	void Slot4(arg *args);
                    	
                    	void Slot5(arg * args);
                    	void Slot6(arg * args);
                    
                        QUuid Slot7();
                        int Slot8();
                    	void Slot9();
                    };
                    
                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on 25 Dec 2018, 07:02 last edited by
                      #13

                      It could be code something like this. Since you are not showing the code we can only guess & try to help you. E.g See the following code. Thread object is created in global scope. When you try start the thread, it will starts its event loop. Simillary I'm just trying to create the event loop object. When you QEventLoop object is created, QApp object should exist.

                      QThread th;
                      
                      int main(int argc, char *argv[])
                      {
                          //th.start();
                          QEventLoop loop;
                          QApplication a(argc, argv);
                          Widget w;
                          w.show();
                      
                          return a.exec();
                      }
                      
                      So you need to start looking at your code for such instances.
                      

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        Mohammedbie
                        wrote on 25 Dec 2018, 07:30 last edited by
                        #14

                        The same SDK ran on windows with no problem with Qt5.12.0 static.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dheerendra
                          Qt Champions 2022
                          wrote on 25 Dec 2018, 08:05 last edited by
                          #15

                          You never know if you have ifdef for windows. You need to identify the specific statement where this issue comes.

                          Dheerendra
                          @Community Service
                          Certified Qt Specialist
                          http://www.pthinks.com

                          1 Reply Last reply
                          1
                          • M Offline
                            M Offline
                            Mohammedbie
                            wrote on 25 Dec 2018, 08:59 last edited by
                            #16

                            Yes on the windows we are using the native functions of the windows but it is used in Networking and logging only and the difference only in the includes and functions name.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              dheerendra
                              Qt Champions 2022
                              wrote on 25 Dec 2018, 11:14 last edited by
                              #17

                              Since you say it is coming from RunSDK method, can you tell us which Qt classes you use inside this class. Where are you creating them ? Also you error is only following statement. Is that correct ?
                              "QEventLoop: Cannot be used without QApplication"
                              There is no "Qt Static" appended at the end.

                              Dheerendra
                              @Community Service
                              Certified Qt Specialist
                              http://www.pthinks.com

                              1 Reply Last reply
                              1
                              • M Offline
                                M Offline
                                Mohammedbie
                                wrote on 25 Dec 2018, 12:37 last edited by Mohammedbie
                                #18

                                @dheerendra

                                There are many levels in this function as I call other functions in it, the first level of the function uses :
                                QString qDebug() QFile QSslCertificate QSslKey QList QByteArray QUuid QLoggingCategory QHash

                                and yes the message is without "Qt Static" I added it as it only happens with Qt static.

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Mohammedbie
                                  wrote on 25 Dec 2018, 12:52 last edited by
                                  #19

                                  I sill can't understand what cause this in Qt static and not in Qt dynamic of the same version as the code in the two cases the same .

                                  K 1 Reply Last reply 25 Dec 2018, 15:09
                                  0
                                  • D Offline
                                    D Offline
                                    dheerendra
                                    Qt Champions 2022
                                    wrote on 25 Dec 2018, 13:11 last edited by dheerendra
                                    #20

                                    I'm going back to basics. Can you create the simple Qt Project with your static Qt build & check if this works ? If this is not working we can see why it is so. Please note. By any chance

                                    1. By any chance QCoreApplication object what you are creating, is it getting destroyed ?
                                    2. Can you try handling destroyed.. signal like the follows in main.cpp
                                    QObject::connect(a,&QApplication::destroyed,[](){
                                            qDebug() << Q_FUNC_INFO << " I am dying " << endl;}
                                        );
                                    
                                    1. This error comes from only one source in Qt & it is QEventLoop. Issue can happen only if the QCoreApp instance is not created, created but destroyed.
                                    2. We have to just focus on the commenting out some code in RunSDK method & figure out.
                                    3. Since we don't have code, I'm proposing different possibilities to check the error.

                                    Dheerendra
                                    @Community Service
                                    Certified Qt Specialist
                                    http://www.pthinks.com

                                    1 Reply Last reply
                                    1
                                    • M Offline
                                      M Offline
                                      Mohammedbie
                                      wrote on 25 Dec 2018, 13:44 last edited by
                                      #21

                                      @dheerendra
                                      That the first step I did after building Qt static I built a console application to test it and it ran with no problem then I ran SignalR tester to test SignalR and it ran without problems.
                                      I tried handling destroyed and "I am dying" never appeared as it should.
                                      I debugged the code in RunSDK method until the error appeared at a get function in SignalR code for getting a url.

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        dheerendra
                                        Qt Champions 2022
                                        wrote on 25 Dec 2018, 14:28 last edited by
                                        #22

                                        @Mohammedbie said in QEventLoop: Cannot be used without QApplication Qt static:

                                        SignalR code for getting a url.

                                        Do you mean that here you are using some QNework* classes to post the URL and get the response from webserver ?

                                        Dheerendra
                                        @Community Service
                                        Certified Qt Specialist
                                        http://www.pthinks.com

                                        1 Reply Last reply
                                        1
                                        • M Mohammedbie
                                          25 Dec 2018, 12:52

                                          I sill can't understand what cause this in Qt static and not in Qt dynamic of the same version as the code in the two cases the same .

                                          K Offline
                                          K Offline
                                          kshegunov
                                          Moderators
                                          wrote on 25 Dec 2018, 15:09 last edited by
                                          #23

                                          @Mohammedbie said in QEventLoop: Cannot be used without QApplication Qt static:

                                          I sill can't understand what cause this in Qt static and not in Qt dynamic of the same version as the code in the two cases the same .

                                          The source may be the same, the way the generated binary/ies are run is different. The most significant difference is with globals/statics initialization. So if you have such, check them first.
                                          Important: QCoreApplication must be the first QObject to be created and the last destroyed, which means you can't have global QObjects.

                                          That's the best I can give you without source code or a stack trace (e.g. running a debug build with QT_FATAL_WARNINGS=1), or any additional information; I'm not about to just guess semi-randomly.

                                          Read and abide by the Qt Code of Conduct

                                          1 Reply Last reply
                                          2

                                          13/30

                                          25 Dec 2018, 07:02

                                          • Login

                                          • Login or register to search.
                                          13 out of 30
                                          • First post
                                            13/30
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved