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)
Forum Updated to NodeBB v4.3 + New Features

how to test a function calculator( QWidget *parent)

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 8 Posters 3.8k 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
    #1

    Every time i call this function calculator(QWidget parent) for testing it shows error :undefined reference to Class::Calculator(QWidget).how can i call this function for testing

    Pablo J. RoginaP 1 Reply Last reply
    0
    • S shravan_121

      Every time i call this function calculator(QWidget parent) for testing it shows error :undefined reference to Class::Calculator(QWidget).how can i call this function for testing

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @shravan_121 help us helping you by showing your code... both the class under testing and the test(s) please

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      5
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

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

        undefined reference to Class::Calculator(QWidget)

        Did you forget to give a body to the method?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

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

          Hi,

          Beside what my fellows already wrote, are properly passing a pointer to a widget for parent ? The error seems to show that you are trying to pass by value rather than pointer.

          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
          4
          • S Offline
            S Offline
            shravan_121
            wrote on last edited by VRonin
            #5

            This is the code:
            Button.h:

            class Button : public QToolButton
            {
                Q_OBJECT
            
            public:
                explicit Button(const QString &text, QWidget *parent = 0);
            

            calculator.h:

            class Calculator : public QWidget
            {
                Q_OBJECT
            
            public:
                Calculator(QWidget *parent = 0);
            

            calculator.cpp:

            Calculator::Calculator(QWidget *parent)
                : QWidget(parent)
            {}
            

            Button.cpp:

            Button::Button(const QString &text, QWidget *parent)
                : QToolButton(parent)
            

            Main.cpp:

            int main(int argc, char *argv[])
            {
                QApplication app(argc, argv);
                Calculator calc;
                calc.show();
                return app.exec();
            }
            

            How can I test this calculator function

            jsulmJ 1 Reply Last reply
            0
            • S shravan_121

              This is the code:
              Button.h:

              class Button : public QToolButton
              {
                  Q_OBJECT
              
              public:
                  explicit Button(const QString &text, QWidget *parent = 0);
              

              calculator.h:

              class Calculator : public QWidget
              {
                  Q_OBJECT
              
              public:
                  Calculator(QWidget *parent = 0);
              

              calculator.cpp:

              Calculator::Calculator(QWidget *parent)
                  : QWidget(parent)
              {}
              

              Button.cpp:

              Button::Button(const QString &text, QWidget *parent)
                  : QToolButton(parent)
              

              Main.cpp:

              int main(int argc, char *argv[])
              {
                  QApplication app(argc, argv);
                  Calculator calc;
                  calc.show();
                  return app.exec();
              }
              

              How can I test this calculator function

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

              @shravan_121 Did you add the calculator.cpp to your pro file?

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

              1 Reply Last reply
              2
              • S Offline
                S Offline
                shravan_121
                wrote on last edited by
                #7

                Test.pro:
                QT += testlib
                QT += gui
                QT +=widgets

                CONFIG += qt console warn_on depend_includepath testcase
                CONFIG -= app_bundle

                TEMPLATE = app

                INCLUDEPATH = C:/Qt/Qt5.12.6/Examples/Qt-5.12.6/widgets/widgets/calculator
                DEPENDPATH = C:/Qt/Qt5.12.6/Examples/Qt-5.12.6/widgets/widgets/calculator

                SOURCES += tst_test1.cpp \

                calculator.pro:
                QT += widgets

                HEADERS = button.h
                calculator.h
                SOURCES = button.cpp
                calculator.cpp
                main.cpp

                install

                target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/calculator
                INSTALLS += target

                J.HilkJ 1 Reply Last reply
                0
                • S shravan_121

                  Test.pro:
                  QT += testlib
                  QT += gui
                  QT +=widgets

                  CONFIG += qt console warn_on depend_includepath testcase
                  CONFIG -= app_bundle

                  TEMPLATE = app

                  INCLUDEPATH = C:/Qt/Qt5.12.6/Examples/Qt-5.12.6/widgets/widgets/calculator
                  DEPENDPATH = C:/Qt/Qt5.12.6/Examples/Qt-5.12.6/widgets/widgets/calculator

                  SOURCES += tst_test1.cpp \

                  calculator.pro:
                  QT += widgets

                  HEADERS = button.h
                  calculator.h
                  SOURCES = button.cpp
                  calculator.cpp
                  main.cpp

                  install

                  target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/calculator
                  INSTALLS += target

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @shravan_121 What are your includes for those classes ?


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

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

                    button.cpp:

                    #include <QtWidgets>
                    #include "button.h"

                    calculator.cpp:

                    #include <QtWidgets>
                    #include <cmath>
                    #include "button.h"
                    #include "calculator.h"

                    main.cpp:

                    #include <QApplication>
                    #include "calculator.h"

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

                      Test.cpp:
                      #include<QTest>
                      #include<calculator.h>
                      #include<button.h>
                      #include<QtWidgets>
                      #include<QDebug>

                      class test1 : public QObject
                      {
                      Q_OBJECT

                      public:
                      test1();
                      ~test1();
                      private slots:
                      void test_case1();
                      void test_case2();
                      private:
                      Calculator *mcalculator;

                      };

                      aha_1980A 1 Reply Last reply
                      0
                      • S shravan_121

                        Test.cpp:
                        #include<QTest>
                        #include<calculator.h>
                        #include<button.h>
                        #include<QtWidgets>
                        #include<QDebug>

                        class test1 : public QObject
                        {
                        Q_OBJECT

                        public:
                        test1();
                        ~test1();
                        private slots:
                        void test_case1();
                        void test_case2();
                        private:
                        Calculator *mcalculator;

                        };

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @shravan_121

                        as @jsulm already said, you must add calculator.cpp to your Test.pro file.

                        Regards

                        Qt has to stay free or it will die.

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

                          After including calculator.cpp i am getting error:QWidget: Must construct a Qapplication before a QWidget. And Thank You all of you for helping me.

                          JonBJ 1 Reply Last reply
                          0
                          • S shravan_121

                            After including calculator.cpp i am getting error:QWidget: Must construct a Qapplication before a QWidget. And Thank You all of you for helping me.

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

                            @shravan_121
                            So you need to obey the message, exactly as it says. You need to construct your QApplication before you can access QWidgets. What else to say?

                            S 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @shravan_121
                              So you need to obey the message, exactly as it says. You need to construct your QApplication before you can access QWidgets. What else to say?

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

                              @JonB Actually I don't know how this works and as i am new to qt I don't know how to construct QApplication

                              JonBJ 1 Reply Last reply
                              0
                              • S shravan_121

                                @JonB Actually I don't know how this works and as i am new to qt I don't know how to construct QApplication

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

                                @shravan_121
                                Follow any example anywhere of how to create a basic Qt (widgets) application. Reading the docs/examples is a good place to start. Without knowing that you won't get anywhere.

                                1 Reply Last reply
                                1
                                • 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

                                          • Login

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