Solved how to test a function calculator( QWidget *parent)
-
@shravan_121 said in how to test a function calculator( QWidget *parent):
but it shows some error
Please post the error
-
@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_OBJECTpublic:
test1();
~test1();private slots:
void test_case1();
void test_case2();private:
Calculator *mcalculator;
};
test1::test1()
{
mcalculator = new Calculator(); //ERROR
}
-
#include <QtTest/QtTest>
#include<QTest>
#include<calculator.h>
#include<button.h>
#include<QtWidgets>
#include<QDebug>
#include<QApplication>
class test1 : public QObject
{
Q_OBJECTpublic:
test1();
~test1();private slots:
void test_case1();
void test_case2();private:
Calculator *mcalculator;
};
test1::test1()
{
mcalculator = new Calculator();//error
}
-
QTEST_APPLESS_MAIN(test1)
#include "tst_test1.moc"
-
@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? -
@JonB Qwidget:Must Create a Qapplication before Qwidget
-
@shravan_121 said in how to test a function calculator( QWidget *parent):
QTEST_APPLESS_MAIN
Why?!
As @SGaist suggested use QTEST_MAIN -
@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 useQTEST_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?
-
@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 . -
@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.