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. Unit teste help
Qt 6.11 is out! See what's new in the release blog

Unit teste help

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    I am creating a unit test to test the return a function. How do I test whether the function is returning an object of type QWidget?

    @#include "LoadUiTest.hpp"

    void LoadUiTest::avalReturn()
    {
    LoadUi loader;
    QString url = "Forms/MainWindow.ui";
    QWidget wid_test;
    QCOMPARE(wid_test, *loader.createForm(&url));
    }
    @
    unsuccessfully

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can't compare widgets like that. Your createForm function should return NULL if it fails.

      On a side note, why are you giving the address of url to createForm ?

      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
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        "isWidgetType()":http://qt-project.org/doc/qt-5/qobject.html#isWidgetType "Returns true if the object is a widget; otherwise returns false."

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Exotic_Devel
          wrote on last edited by
          #4

          Worked with:

          @void LoadUiTest::avalReturn()
          {
          LoadUi loader;
          QString url = "Forms/MainWindow.ui";
          QVERIFY(loader.createForm(&url)->isWidgetType());
          }
          @

          SGaist, I created a class to generate forms with QUiLoader. url is the location of the ui file

          Thanks people.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            That I understood, the question is why use a pointer to a QString ? It's as implicitly shared class, you should rather pass a const reference.

            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

            • Login

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