Problems with using QTimer

2019-07-29 07:25发布

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 timer();

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.

标签: qt timer
2条回答
我只想做你的唯一
2楼-- · 2019-07-29 08:16

Just add

#include <QTimer>

to the start of your source file. And go back to your first version:

QTimer *timer = new QTimer();
查看更多
倾城 Initia
3楼-- · 2019-07-29 08:18

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.

查看更多
登录 后发表回答