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. Forcing events with QOpenGLWidget (testing)
QtWS25 Last Chance

Forcing events with QOpenGLWidget (testing)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 525 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
    anthel
    wrote on last edited by
    #1

    Greetings:

    I am trying to implement some tests within my QOpenGLWidget application; for example, a test might be to setup a 400px400px window, left click on location (1,1), move to location (200,200), release (these three operations effectively rotate the object), and then do some project/unproject to make sure the right things are at the right places. Anyways, I created functions that manually perform these operations and then call update() however the image only displays after the operations are finished and when it shows it is in the starting position. I believe I am not invoking the test in an appropriate way for the underlying objects to do what they're supposed to do. My application is similar in construction to Qt's "hellogl2" sample application here.

    • What is the preferred way to initiate these tests? I currently set a boolean within the widget class for testing and do a check on it within paintGL() which kicks of the tests. This feels clunky so I am wondering if there is a better way.
    • I made my own functions that do the same things that my mousePressEvent(), mouseMoveEvent(), and mouseReleaseEvent() functions perform; these are what the testing function calls. Is there a better way for me to tell Qt about these events so I can use the actual aforementioned mouse*Event() functions instead of the ones made for testing?

    I appreciate any guidance this forum can provide. Thank you for your help with this.

    Kind regards,
    Anthony

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Are you looking for testlib framework ?

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

      A 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Are you looking for testlib framework ?

        A Offline
        A Offline
        anthel
        wrote on last edited by
        #3

        Thank you @dheerendra for your reply. I created a command line argument to my application for running these GUI tests and was hoping to not have separate executables for running the tests (this way, if there are issues with the application a user can run the tests directly). Can I achieve this with QTest? Thank you for your help with this.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Just look at the QTest lib in Assistant & try running some examples. You will get the feel of it. It will not take much time to check this.

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

          A 1 Reply Last reply
          0
          • dheerendraD dheerendra

            Just look at the QTest lib in Assistant & try running some examples. You will get the feel of it. It will not take much time to check this.

            A Offline
            A Offline
            anthel
            wrote on last edited by
            #5

            Thank you @dheerendra for your reply. I spent some time looking at Qt Test and am unsure of how to get it to drive my whole application rather than just some small portions of it. The click and drag that I want to do exercises quite a few of my custom methods within QOpenGLWidget. So, how do I structure the test object to be able to do this since a lot of things are handled under the hood by Qt? My main.cpp does the following to kick everything off. How would the test case appropriately start things so I could, then, add the appropriate QTest::mouseClick() operations? Thank you for your help with this.

            QApplication app(argc, argv);
            QSurfaceFormat fmt;
            MainWindow mainWindow;
            fmt.setDepthBufferSize(24);
            QSurfaceFormat::setDefaultFormat(fmt);
            mainWindow.resize(mainWindow.sizeHint());
            desktopArea = QApplication::desktop()->width() *
                QApplication::desktop()->height();
            widgetArea = mainWindow.width() * mainWindow.height();
            if (((float)widgetArea / (float)desktopArea) < 0.75f)
                mainWindow.show();
            else
                mainWindow.showMaximized();
            return app.exec();
            
            1 Reply Last reply
            0
            • A Offline
              A Offline
              anthel
              wrote on last edited by
              #6

              Greetings:

              I created the following test object for the case above. The issue I encounter is how to provide an appropriate QWindow or QWidget pointer to QTest::mouseClick(). My MainWindow class inherits from QMainWindow and sets in motion the creation of my Window class (which inherits from QWidget) which creates my GLWidget class (which inherits from QOpenGLWidget). Do I need to ultimately circumvent all of this and manually create these items? Thank you for your help with this.

              
              #include <QtTest/QtTest>       // Qt Test class
              #include "glwidget.h"          // GLWidget class
              #include "mainwindow.h"        // MainWindow class
              
              class TestHT: public QObject
              {
                  Q_OBJECT
              
              private slots:
                  void dragTopMiddleToCenter();
              };
              
              void TestHT::dragTopMiddleToCenter()
              {
                  // Test that drags from top middle to center
              
                  // initialize renderable area
                  QSurfaceFormat fmt;
              
                  // initialize main window
                  MainWindow mainWindow;
              
                  // set depth
                  fmt.setDepthBufferSize(24);
              
                  // finalize renderable area
                  QSurfaceFormat::setDefaultFormat(fmt);
              
                  // handle transparency
                  GLWidget::setTransparent(parser.isSet(transparentOption));
                  if (GLWidget::isTransparent())
                  {
                      mainWindow.setAttribute(Qt::WA_TranslucentBackground);
                      mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
                  }
              
                  // setup window size
                  mainWindow.resize(mainWindow.sizeHint());
                  desktopArea = QApplication::desktop()->width() *
                      QApplication::desktop()->height();
                  widgetArea = mainWindow.width() * mainWindow.height();
              
                  // display window
                  if (((float)widgetArea / (float)desktopArea) < 0.75f)
                      mainWindow.show();
                  else
                      mainWindow.showMaximized();
              
                  // do mouse click
                  QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1), 400);
              
                  QVERIFY(1 == 1);
              }
              
              
              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