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. Qt Unit testing Error Please Help!!
Forum Updated to NodeBB v4.3 + New Features

Qt Unit testing Error Please Help!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 326 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.
  • A Offline
    A Offline
    Amogh
    wrote on 18 Oct 2019, 11:08 last edited by
    #1

    I was trying to execute the sample unit test for Gui Element !
    #include <QString>
    #include <QtTest>
    #include<QtWidgets>

    class Sample_Unit_Testing : public QObject
    {
    Q_OBJECT

    public:
    Sample_Unit_Testing();

    private Q_SLOTS:
    void tst_Gui();
    };
    void Sample_Unit_Testing::tst_Gui()
    {
    QLineEdit line_edit;
    QTest::keyClicks(&line_edit,"abcd");
    QCOMPARE(line_edit.text(),QString("abcd"));
    }

    this is my code, When i run this code i get an error which says

    QFATAL : Sample_Unit_Testing::tst_Gui() QWidget: Must construct a QApplication before a QWidget
    FAIL! : Sample_Unit_Testing::tst_Gui() Received a fatal error.

    Can anybody explain it me about the error and help??

    A 1 Reply Last reply 18 Oct 2019, 11:49
    0
    • A Amogh
      18 Oct 2019, 11:08

      I was trying to execute the sample unit test for Gui Element !
      #include <QString>
      #include <QtTest>
      #include<QtWidgets>

      class Sample_Unit_Testing : public QObject
      {
      Q_OBJECT

      public:
      Sample_Unit_Testing();

      private Q_SLOTS:
      void tst_Gui();
      };
      void Sample_Unit_Testing::tst_Gui()
      {
      QLineEdit line_edit;
      QTest::keyClicks(&line_edit,"abcd");
      QCOMPARE(line_edit.text(),QString("abcd"));
      }

      this is my code, When i run this code i get an error which says

      QFATAL : Sample_Unit_Testing::tst_Gui() QWidget: Must construct a QApplication before a QWidget
      FAIL! : Sample_Unit_Testing::tst_Gui() Received a fatal error.

      Can anybody explain it me about the error and help??

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 18 Oct 2019, 11:49 last edited by
      #2

      Hi @Amogh,

      do you use QTEST_MAIN? If not, please show your main function resp. use QTEST_MAIN.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      2

      1/2

      18 Oct 2019, 11:08

      • Login

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