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. 单元测试问题QWidget: Must construct a QApplication before a QWidget
Qt 6.11 is out! See what's new in the release blog

单元测试问题QWidget: Must construct a QApplication before a QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.0k 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.
  • D Offline
    D Offline
    dilipa
    wrote on last edited by
    #1

    我尝试QT 单元测试 使用教程例子 却遇到了问题
    9a621d1e-cf13-40d8-891b-df550df677af-image.png
    一个致命的问题QWidget: Must construct a QApplication before a QWidget
    828225b2-fbd2-4899-8b55-5f68100fe4f4-image.png

    jsulmJ 1 Reply Last reply
    0
    • D dilipa

      我尝试QT 单元测试 使用教程例子 却遇到了问题
      9a621d1e-cf13-40d8-891b-df550df677af-image.png
      一个致命的问题QWidget: Must construct a QApplication before a QWidget
      828225b2-fbd2-4899-8b55-5f68100fe4f4-image.png

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

      @dilipa Please read documentation: https://doc.qt.io/qt-5/qtest.html#QTEST_APPLESS_MAIN
      Especially this: "but doesn't instantiate a QApplication"...

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

      D 1 Reply Last reply
      2
      • jsulmJ jsulm

        @dilipa Please read documentation: https://doc.qt.io/qt-5/qtest.html#QTEST_APPLESS_MAIN
        Especially this: "but doesn't instantiate a QApplication"...

        D Offline
        D Offline
        dilipa
        wrote on last edited by
        #3

        @jsulm 我的问题得到了解决,非常感谢,但同时我想到在创建项目时,支持选择GUI,是否应该在选择的同时自动生成QTEST_MAIN()而非QTEST_APPLESS_MAIN()。

        jsulmJ 1 Reply Last reply
        0
        • D dilipa

          @jsulm 我的问题得到了解决,非常感谢,但同时我想到在创建项目时,支持选择GUI,是否应该在选择的同时自动生成QTEST_MAIN()而非QTEST_APPLESS_MAIN()。

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

          @dilipa I don't speak Chinese...

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

          1 Reply Last reply
          1
          • D Offline
            D Offline
            dilipa
            wrote on last edited by
            #5

            @jsulm Sorry, I didn't think about this, my problem has been solved, thank you very much, but at the same time I wonder if I should automatically generate QTEST_MAIN () instead of QTEST_APPLESS_MAIN () when creating projects that support GUI selection.

            jsulmJ 1 Reply Last reply
            1
            • D dilipa

              @jsulm Sorry, I didn't think about this, my problem has been solved, thank you very much, but at the same time I wonder if I should automatically generate QTEST_MAIN () instead of QTEST_APPLESS_MAIN () when creating projects that support GUI selection.

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

              @dilipa said in 单元测试问题QWidget: Must construct a QApplication before a QWidget:

              QTEST_MAIN () instead of QTEST_APPLESS_MAIN () when creating projects that support GUI selection

              Yes, as soon as GUI is involved you can't use QTEST_APPLESS_MAIN

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

              1 Reply Last reply
              0

              • Login

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