Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unit teste help

    General and Desktop
    3
    5
    786
    Loading More Posts
    • 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
      Exotic_Devel last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • A
          andreyc last edited by

          "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 Reply Quote 0
          • E
            Exotic_Devel last edited by

            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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • First post
                Last post