I am new to Qt. I made some simple changes to an existing Qt application, but I haven't created anything from scratch yet.
I also don't have much experience with some aspects of C ++ in general (class inheritance, etc.).
I created a new Code :: Blocks Qt4 project and changed the template a bit. I added two files.
Now the project contains three files: main.cpp, app.h and app.cpp.
This is the contents of main.cpp :
#include <QTimer> #include "app.h" int main(int argc, char* argv[]) { TestApp app(argc, argv); QTimer::singleShot(1000, &app, SLOT(timeout())); return app.exec(); }
Here is what app.h looks like :
#ifndef APP_H_INCLUDED #define APP_H_INCLUDED #include <QApplication> class TestApp: public QApplication { public: TestApp(int &argc, char **argv); public slots: void timeout(); }; #endif
And this is app.cpp :
#include "app.h" #include <QDebug> TestApp::TestApp(int &argc, char **argv): QApplication(argc, argv) { } void TestApp::timeout() { qDebug() << "timeout called"; }
I expected the program to display a timeout one second after starting. Unfortunately this does not work. When QTimer::singleShot() is called, the console says:
Object::connect: No such slot QApplication::timeout() in [path to the main.cpp file] Object::connect: (receiver name: 'QtTests')
I have no idea how to deal with this. Thank you in advance.
c ++ inheritance qt signals-slots connect
rhino
source share