Problems with using QTimer
I am having a small problem with QTimer
. Whenever I use QTimer
it shows me this error
QTimer *timer = new QTimer();
error: invalid use of incomplete type 'struct QTimer'
So I tried this
QTimer ti开发者_运维知识库mer();
Now I got rid of that error but when I use members inside the QTimer it shows me these errors. For example
timer.start(1000);
or
timer->start(1000);
error: request for member 'start' in 'timer', which is of non-class type 'QTimer*()'
I tried to include QTimer but it shows me that there is no such file or directory error.
I am using the Code::Blocks IDE.
Just add
#include <QTimer>
to the start of your source file. And go back to your first version:
QTimer *timer = new QTimer();
There should be a QTimer header. If it's not found then you might have your include paths set up wrong. If it's not there, reinstall your Qt SDK.
Your code QTimer timer();
is wrong. It does not create a QTimer, but you declare a function 'timer', with return type 'QTimer'. It should be QTimer timer;
although that would most likely give you similar issues if it can't find the header.
精彩评论