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. how to test a function calculator( QWidget *parent)
Qt 6.11 is out! See what's new in the release blog

how to test a function calculator( QWidget *parent)

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 8 Posters 4.4k Views 2 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.
  • S Offline
    S Offline
    shravan_121
    wrote on last edited by
    #16

    I have the application created but for testing that application I am facing this error.In that actual application Application is constructed in the main function.

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

      Please read the QtTest module tutorials they show how to write unit tests.

      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
      3
      • S Offline
        S Offline
        shravan_121
        wrote on last edited by
        #18

        I have gone through the document about unit testing.Now I have some idea on inbuilt qttest functions.But I need to clear the error of QApplication construction in QtTest application.Can Any one help me solving this.

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

          Did you add the QTEST_MAIN related lines as described at the bottom of the GUI related tutorials ?

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

          S 1 Reply Last reply
          2
          • SGaistS SGaist

            Did you add the QTEST_MAIN related lines as described at the bottom of the GUI related tutorials ?

            S Offline
            S Offline
            shravan_121
            wrote on last edited by
            #20

            @SGaist I tried It but it shows some error I don't know how can you give me a sample of it
            how to add QApplication related lines because i am unclear about the concept.

            jsulmJ 1 Reply Last reply
            0
            • S shravan_121

              @SGaist I tried It but it shows some error I don't know how can you give me a sample of it
              how to add QApplication related lines because i am unclear about the concept.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #21

              @shravan_121 said in how to test a function calculator( QWidget *parent):

              but it shows some error

              Please post the error

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

              S 1 Reply Last reply
              1
              • jsulmJ jsulm

                @shravan_121 said in how to test a function calculator( QWidget *parent):

                but it shows some error

                Please post the error

                S Offline
                S Offline
                shravan_121
                wrote on last edited by
                #22

                @jsulm
                Test.Cpp:
                #include <QtTest/QtTest>
                #include<QTest>
                #include<calculator.h>
                #include<button.h>
                #include<QtWidgets>
                #include<QDebug>
                #include<QApplication>
                class test1 : public QObject
                {
                Q_OBJECT

                public:
                test1();
                ~test1();

                private slots:
                void test_case1();
                void test_case2();

                private:

                Calculator *mcalculator;
                

                };

                test1::test1()

                {

                mcalculator = new Calculator(); //ERROR

                }

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shravan_121
                  wrote on last edited by shravan_121
                  #23

                  #include <QtTest/QtTest>
                  #include<QTest>
                  #include<calculator.h>
                  #include<button.h>
                  #include<QtWidgets>
                  #include<QDebug>
                  #include<QApplication>
                  class test1 : public QObject
                  {
                  Q_OBJECT

                  public:
                  test1();
                  ~test1();

                  private slots:
                  void test_case1();
                  void test_case2();

                  private:

                  Calculator *mcalculator;
                  

                  };

                  test1::test1()

                  {

                  mcalculator = new Calculator();//error

                  }

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shravan_121
                    wrote on last edited by
                    #24

                    QTEST_APPLESS_MAIN(test1)

                    #include "tst_test1.moc"

                    JonBJ jsulmJ 2 Replies Last reply
                    0
                    • S shravan_121

                      QTEST_APPLESS_MAIN(test1)

                      #include "tst_test1.moc"

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #25

                      @shravan_121
                      So the compiler just reports "Error" on some line? It does not have anything further than that, it just goes "Error" with no explanation? Because obviously if it did output a whole line of explanation with the error message you would paste that here when asking for help, and you have been asked for the error, wouldn't you?

                      S 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @shravan_121
                        So the compiler just reports "Error" on some line? It does not have anything further than that, it just goes "Error" with no explanation? Because obviously if it did output a whole line of explanation with the error message you would paste that here when asking for help, and you have been asked for the error, wouldn't you?

                        S Offline
                        S Offline
                        shravan_121
                        wrote on last edited by
                        #26

                        @JonB Qwidget:Must Create a Qapplication before Qwidget

                        JonBJ 1 Reply Last reply
                        0
                        • S shravan_121

                          QTEST_APPLESS_MAIN(test1)

                          #include "tst_test1.moc"

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #27

                          @shravan_121 said in how to test a function calculator( QWidget *parent):

                          QTEST_APPLESS_MAIN

                          Why?!
                          As @SGaist suggested use QTEST_MAIN

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

                          1 Reply Last reply
                          4
                          • S shravan_121

                            @JonB Qwidget:Must Create a Qapplication before Qwidget

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #28

                            @shravan_121
                            I don't mean to be rude, but did you really read what @SGaist and others told you at look at? He suggested you use QTEST_MAIN, and gave you the link:

                            Implements a main() function that instantiates an application object

                            And you show us a snippet (don't know where from):

                            QTEST_APPLESS_MAIN(test1)
                            #include "tst_test1.moc"
                            

                            So you chose to use QTEST_APPLESS_MAIN, where https://doc.qt.io/qt-5/qtest.html#QTEST_APPLESS_MAIN states:

                            Behaves like QTEST_MAIN(), but doesn't instantiate a QApplication object. Use this macro for really simple stand-alone non-GUI tests.

                            So why did you choose this, and why do you ask what to do about

                            Qwidget:Must Create a Qapplication before Qwidget

                            given that you have chosen something which states it does not create an application object and is for use in non-GUI situations?

                            S 1 Reply Last reply
                            6
                            • JonBJ JonB

                              @shravan_121
                              I don't mean to be rude, but did you really read what @SGaist and others told you at look at? He suggested you use QTEST_MAIN, and gave you the link:

                              Implements a main() function that instantiates an application object

                              And you show us a snippet (don't know where from):

                              QTEST_APPLESS_MAIN(test1)
                              #include "tst_test1.moc"
                              

                              So you chose to use QTEST_APPLESS_MAIN, where https://doc.qt.io/qt-5/qtest.html#QTEST_APPLESS_MAIN states:

                              Behaves like QTEST_MAIN(), but doesn't instantiate a QApplication object. Use this macro for really simple stand-alone non-GUI tests.

                              So why did you choose this, and why do you ask what to do about

                              Qwidget:Must Create a Qapplication before Qwidget

                              given that you have chosen something which states it does not create an application object and is for use in non-GUI situations?

                              S Offline
                              S Offline
                              shravan_121
                              wrote on last edited by
                              #29

                              @JonB Thanks for helping me out.And sorry for asking some silly questions it makes me learn and I want help from people like you for me to grow.
                              Once again Thank you all .

                              JonBJ 1 Reply Last reply
                              2
                              • S shravan_121

                                @JonB Thanks for helping me out.And sorry for asking some silly questions it makes me learn and I want help from people like you for me to grow.
                                Once again Thank you all .

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #30

                                @shravan_121
                                No problems, best of luck. :)

                                When you do have questions, try to explain and show what precisely is going wrong. And take the time to read through the Qt documentation pages, I know there is a lot there but it's also really helpful.

                                1 Reply Last reply
                                1

                                • Login

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