mercredi 29 juin 2016

Error when calling qExec "no known conversion for argument 1 to QObject"

I'm trying to create tests for a c++ application with QtTest. The three relevent files that I have are: GuiTests.cpp which contains my main function, testsuite1.cpp which contains my tests and testsuite1.h which contains the definitions of my tests. I created these files with help from different guides, for example this one: http://ift.tt/294dWDx.

When I try to build I get this error:

no matching function for call to 'qExec(TestSuite1 (*)(), int&, char**&)'

no known conversion for argument 1 from 'TestSuite1 (*)()' to 'QObject*'

I don't understand why, as you can see in testsuite.h below TestSuite1 is a QObject. The funny thing is this exact code (I am pretty sure) worked before but then I fiddled around with passing argc and argv to guiTest() for a while, and after I removed argc and argv and went back to what I had before (what I currently have, please see the files below) I got this error.

I've been trying to solve this problem for a long time and I can't find any answers online, so please help me, any help is appreciated. Thanks!

GuiTests.cpp

#include "testsuite1.h"
#include <QtTest>
#include <QCoreApplication>

int main(int argc, char** argv) {
    TestSuite1 testSuite1();
    return QTest::qExec(&testSuite1, argc, argv);
}

testsuite1.h

#ifndef TESTSUIT1_H
#define TESTSUIT1_H

#include <QMainWindow>
#include <QObject>
#include <QWidget>
#include <QtTest>

class TestSuite1 : public QObject {
Q_OBJECT
public:
    TestSuite1();
    ~TestSuite1();

private slots:
    // functions executed by QtTest before and after test suite
    void initTestCase();
    void cleanupTestCase();

    // functions executed by QtTest before and after each test
    //void init();
    //void cleanup();

    // test functions
    void testSomething();
    void guiTest();
};

#endif // TESTSUIT1_H

testsuite1.cpp

#include "testsuite1.h"
#include <QtWidgets>
#include <QtCore>
#include <QtTest>

TestSuite1::TestSuite1()
{

}

TestSuite1::~TestSuite1()
{

}

void TestSuite1::initTestCase()
{

}

void TestSuite1::cleanupTestCase()
{

}

void TestSuite1::guiTest()
{
    QVERIFY(1+1 == 2);
}

void TestSuite1::testSomething()
{
    QLineEdit lineEdit;

    QTest::keyClicks(&lineEdit, "hello world");

    QCOMPARE(lineEdit.text(), QString("hello world"));

    //QVERIFY(1+1 == 2);
}

//QTEST_MAIN(TestSuite1)
//#include "TestSuite1.moc"

Aucun commentaire:

Enregistrer un commentaire