Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. International
  3. German
  4. Error bei Unittest unverständlich "QJSEngine: Must construct a QCoreApplication before a QJSEngine"
Qt 6.12 LTS is out! See what's new in the release blog

Error bei Unittest unverständlich "QJSEngine: Must construct a QCoreApplication before a QJSEngine"

Scheduled Pinned Locked Moved Solved German
12 Posts 3 Posters 3.7k Views
  • 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.
  • G Galilio

    Hallo zusammen,

    ich bin dabei einen Unittest zu schreiben.
    bei die beiden Zeile:

        QQmlEngine engine;
        engine.addImportPath("qrc:/");
    

    QJSEngine: Must construct a QCoreApplication before a QJSEngine

    und folgenden Warnungen:
    QCoreApplication::applicationDirPath: Please instantiate the QApplication object first
    QEventLoop: Cannot be used without QApplication

    Ich verstehe nicht was ist dann falsch?

    Danke in voraus

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Galilio Du brauchst eine Instanz von QCoreApplication:

    QCoreApplication(...);
    QQmlEngine engine;
    engine.addImportPath("qrc:/");
    

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • G Offline
      G Offline
      Galilio
      wrote on last edited by
      #3

      Kannst du bir mir sagen warum es unbedingt einen Instanz notwendig

      Danke

      aha_1980A jsulmJ 2 Replies Last reply
      0
      • G Galilio

        Kannst du bir mir sagen warum es unbedingt einen Instanz notwendig

        Danke

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Galilio Q(Core)Application ist der Motor jedes Qt Programms. So wie ein Auto ohne Motor nicht fährt, kann ein Qt-Programm ohne QCoreApplication nicht funktionieren.

        Grüße

        Qt has to stay free or it will die.

        1 Reply Last reply
        1
        • G Galilio

          Kannst du bir mir sagen warum es unbedingt einen Instanz notwendig

          Danke

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @Galilio Hier findest du die Info: https://doc.qt.io/qt-5/qcoreapplication.html
          Das ist auch lesenswert: https://wiki.qt.io/Threads_Events_QObjects

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • G Offline
            G Offline
            Galilio
            wrote on last edited by
            #6

            Hallo,

            danke für die Antwort.
            Ich bin dabei einen QML Unittest zu schreiben und habe gedacht, dass ich den QCoreApplicaton gar nicht brauche und weiss ich ehrlich gesagt woher soll ich die überhaupt instanziere.

            Es handelt sich um einen Qt Quick Application .

            G 1 Reply Last reply
            0
            • G Galilio

              Hallo,

              danke für die Antwort.
              Ich bin dabei einen QML Unittest zu schreiben und habe gedacht, dass ich den QCoreApplicaton gar nicht brauche und weiss ich ehrlich gesagt woher soll ich die überhaupt instanziere.

              Es handelt sich um einen Qt Quick Application .

              G Offline
              G Offline
              Galilio
              wrote on last edited by
              #7

              @Galilio
              Konkreter gefragt: Mein Ziel wäre einen Unit test für einen QML Datei zu schreiben.
              folgende habe ich gemacht:
              1)Das QML Datei (Der zu testen ist)
              2)tst_QML datei (Wo die State und die Geometrie festgelegt sind)
              3)Das Unittest (mit dem ich gerade bin), der so aussieht:

              class CPP_QML_Name :public QObject
              {
              	Q_OBJECT
              	
              	...
              	private slots:
              	void initTestCase();
              	void test_case1();
              	....
              	};
              	.....// Die Implementierung
              void CPP_QML_Name initTestCase()
              {
              	QQmlEngine engine;
                  engine.addImportPath("qrc:/");
              	QQmlComponent component(&engine);
                  component.loadUrl(QUrl("qrc:/tst_QQtQMLTestFileName.qml"));
                  QVERIFY(component.isReady());
              	...
              	// Bis hier was ist dan falsch?
              }	
              	
              	
              	
              QTEST_APPLESS_MAIN(CPP_QML_Name)
              
              #include "CPP_QML_Name.moc"
              

              Ich benutze übrigen Qt Version 5.9.1

              Danke

              aha_1980A jsulmJ 2 Replies Last reply
              0
              • G Galilio

                @Galilio
                Konkreter gefragt: Mein Ziel wäre einen Unit test für einen QML Datei zu schreiben.
                folgende habe ich gemacht:
                1)Das QML Datei (Der zu testen ist)
                2)tst_QML datei (Wo die State und die Geometrie festgelegt sind)
                3)Das Unittest (mit dem ich gerade bin), der so aussieht:

                class CPP_QML_Name :public QObject
                {
                	Q_OBJECT
                	
                	...
                	private slots:
                	void initTestCase();
                	void test_case1();
                	....
                	};
                	.....// Die Implementierung
                void CPP_QML_Name initTestCase()
                {
                	QQmlEngine engine;
                    engine.addImportPath("qrc:/");
                	QQmlComponent component(&engine);
                    component.loadUrl(QUrl("qrc:/tst_QQtQMLTestFileName.qml"));
                    QVERIFY(component.isReady());
                	...
                	// Bis hier was ist dan falsch?
                }	
                	
                	
                	
                QTEST_APPLESS_MAIN(CPP_QML_Name)
                
                #include "CPP_QML_Name.moc"
                

                Ich benutze übrigen Qt Version 5.9.1

                Danke

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @Galilio said in Error bei Unittest unverständlich "QJSEngine: Must construct a QCoreApplication before a QJSEngine":

                QTEST_APPLESS_MAIN

                Ersetze das durch QTEST_MAIN und es wird alles funktionieren.

                Qt has to stay free or it will die.

                1 Reply Last reply
                2
                • G Galilio

                  @Galilio
                  Konkreter gefragt: Mein Ziel wäre einen Unit test für einen QML Datei zu schreiben.
                  folgende habe ich gemacht:
                  1)Das QML Datei (Der zu testen ist)
                  2)tst_QML datei (Wo die State und die Geometrie festgelegt sind)
                  3)Das Unittest (mit dem ich gerade bin), der so aussieht:

                  class CPP_QML_Name :public QObject
                  {
                  	Q_OBJECT
                  	
                  	...
                  	private slots:
                  	void initTestCase();
                  	void test_case1();
                  	....
                  	};
                  	.....// Die Implementierung
                  void CPP_QML_Name initTestCase()
                  {
                  	QQmlEngine engine;
                      engine.addImportPath("qrc:/");
                  	QQmlComponent component(&engine);
                      component.loadUrl(QUrl("qrc:/tst_QQtQMLTestFileName.qml"));
                      QVERIFY(component.isReady());
                  	...
                  	// Bis hier was ist dan falsch?
                  }	
                  	
                  	
                  	
                  QTEST_APPLESS_MAIN(CPP_QML_Name)
                  
                  #include "CPP_QML_Name.moc"
                  

                  Ich benutze übrigen Qt Version 5.9.1

                  Danke

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Galilio Deine Test-App ist keine reine QML app, sie ist eine C++ application, die Klassen benutzt, welche eine Event-Loop erfordern.

                  Benutze https://doc.qt.io/qt-5/qtest.html#QTEST_MAIN statt QTEST_APPLESS_MAIN.
                  QTestMain erstellt eine QApplication Instanz.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • G Offline
                    G Offline
                    Galilio
                    wrote on last edited by
                    #10

                    Aber "QTEST_MAIN " ist in Qt Version 5.9.1 nicht vorhanden

                    jsulmJ 1 Reply Last reply
                    0
                    • G Galilio

                      Aber "QTEST_MAIN " ist in Qt Version 5.9.1 nicht vorhanden

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Galilio said in Error bei Unittest unverständlich "QJSEngine: Must construct a QCoreApplication before a QJSEngine":

                      Aber "QTEST_MAIN " ist in Qt Version 5.9.1 nicht vorhanden

                      https://doc.qt.io/qt-5.9/qtest.html#QTEST_MAIN ?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      G 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Galilio said in Error bei Unittest unverständlich "QJSEngine: Must construct a QCoreApplication before a QJSEngine":

                        Aber "QTEST_MAIN " ist in Qt Version 5.9.1 nicht vorhanden

                        https://doc.qt.io/qt-5.9/qtest.html#QTEST_MAIN ?

                        G Offline
                        G Offline
                        Galilio
                        wrote on last edited by
                        #12

                        @jsulm

                        Vielen dank

                        1 Reply Last reply
                        2

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt
                        • Unsolved