Problems with using QTimer

一笑奈何 提交于 2019-12-24 17:25:02

问题


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.


回答1:


Just add

#include <QTimer>

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

QTimer *timer = new QTimer();



回答2:


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.



来源:https://stackoverflow.com/questions/5961072/problems-with-using-qtimer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!