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 test empty window

Qt test empty window

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt test
5 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    mk33
    wrote on 10 May 2016, 13:38 last edited by
    #1

    Hi,
    I create simple GUI application (QMainWindow with QListWidget, QComboBox and QPushButton) and test cpp file:

    #include <QString>
    #include <QtTest>
    #include <QCoreApplication>
    
    #include "../App/mainwindow.h"
    
    #include <QComboBox>
    
    class TestsTest : public QObject
    {
        Q_OBJECT
    
    public:
        TestsTest();
    
    private Q_SLOTS:
        void testCase1();
    
    private:
        MainWindow* mainWindow_;
    };
    
    TestsTest::TestsTest()
    {
        mainWindow_ = new MainWindow();
        mainWindow_->show();
    }
    
    void TestsTest::testCase1()
    {
        QString comboBoxName = "comboBox";
        QComboBox* comboBox = mainWindow_->findChild<QComboBox*>(comboBoxName);
        if (comboBox)
        {
            QTest::qSleep(1000);
            QTest::mouseClick(comboBox, Qt::LeftButton);
            QTest::qSleep(1000);
        }
        else
        {
            QFAIL("invalid combobox name");
        }
    }
    
    QTEST_MAIN(TestsTest)
    
    #include "tst_teststest.moc"
    

    Test create empty window (no widgets) but QFAIL will not be executed. I debug code and QComboBox is found. I will record video from the test and it is not possible at the moment. I use Qt 5.6.0 MinGW 32-bit on Windows 7.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 May 2016, 20:51 last edited by
      #2

      Hi and welcome to devnet,

      From your description MainWindow should contain a combo box and in your test you create that MainWindow, so it does sound reasonable that the QComboBox is found, no ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mk33
        wrote on 11 May 2016, 05:56 last edited by mk33 5 Nov 2016, 05:58
        #3

        Yes, mainwindow contains combobox, but screenshot shows something else. Yes, this is only image, but I want create video record from testing. Is it normal? Screenshot from Qt 5.6 64bit linux.
        image

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 11 May 2016, 06:07 last edited by
          #4

          The problem could be that you have two QTest::qSleep(1000); calls which block the event loop.
          See here: http://doc.qt.io/qt-5/qtest.html#qSleep
          "Sleeps for ms milliseconds, blocking execution of the test. qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. Use qWait() to do non-blocking sleeping."

          That means, your UI cannot be drown properly. Try to use qWait.

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

          M 1 Reply Last reply 11 May 2016, 06:43
          1
          • J jsulm
            11 May 2016, 06:07

            The problem could be that you have two QTest::qSleep(1000); calls which block the event loop.
            See here: http://doc.qt.io/qt-5/qtest.html#qSleep
            "Sleeps for ms milliseconds, blocking execution of the test. qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. Use qWait() to do non-blocking sleeping."

            That means, your UI cannot be drown properly. Try to use qWait.

            M Offline
            M Offline
            mk33
            wrote on 11 May 2016, 06:43 last edited by
            #5

            @jsulm Thank you, problem solved.

            1 Reply Last reply
            0

            3/5

            11 May 2016, 05:56

            • Login

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