How does the QTimer work?
-
Hi,
I am learning about QTimer and I am currently reading the documentation "here.":http://qt-project.org/doc/qt-4.8/QTimer.html Specifically, I am examining this piece of code:
@
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);@What I mostly do not understand is how the
connect()
function works. Is it in a class of some sort? What do the second, third, and fourth arguments "do"? I also realize thethis
operator, which means that the function must be called inside a class member. Because I can call this function within the "Clock_Application" class, which is the name of my project as well. That must mean it is part of Q_OBJECT?Also, are signals and slots QT things, because I have no idea what they are?
-
connect is a static method of "QObject,":/doc/qt-4.8/qobject.html and is one of the most important methods in Qt programming, as it is responsible for setting up connections between "Signals and Slots.":/doc/qt-4.8/signalsandslots.html
It's one of the fundamentals, so you're best to go study "those":/doc/qt-4.8/how-to-learn-qt.html before getting too far into things.
Good luck!
-
bq. connect is a static method of QObject, and is one of the most important methods in Qt programming, as it is responsible for setting up connections between Signals and Slots.
It’s one of the fundamentals, so you’re best to go study those before getting too far into things.
Good luck!Thanks for the info. I am not too interested in developing anything with Qt, but rather I use the IDE to learn the C++ language. When I created my own timer widget, I realized it got unresponsive, because Qt widget projects unfortunately do not take infinite loops, without using QCoreApplication::processEvents(). I thought learning about QTimer would help, but I realized it was really based off of the Qt framework.
Is this the case with all the IDEs with widget systems, such as MS Visual Studio and Code::Blocks? Do they all have their own "system"?
-
Anything with a Q in front of it is going to be Qt-related.
As for the IDEs and "systems", generally IDEs are designed to work within a certain environment and support extension libraries, and such. However, Qt Creator and MSVS and Eclipse (etc.) can happily be used to develop pure C++ apps. You just have to understand the boundaries of what is native C++ and what is provided by the Toolkits that they tend to want to integrate with.
-
Cool, so if I ran a program that uses Q libraries like QString and QRegExp on a computer with none of those libraries, would it work?
-
If you link the program dynamically to desired Qt libraries...then yes. Aka, if QtCore4.dll is in the same folder as your executable that you are trying to run then it should pick up the libraries.
Qt is not a standard...you must download the sources or SDK, compile it (static or dynamic), and link to them. As in any library or framework.
-
Darn it. I tried turning my timer into a thread to reduce the lagginess of the widget, but somehow, I cannot include the
Ui
namespace in the thread..@
void Clock_Application::timer_Start()
{
timingThread Timer;
Timer.start();
}bool timing_Stopwatch = false;
void timingThread::run()
{
using namespace Ui;// more code }
}
@ -
Using a thread to run a timer is a Bad Idea(TM). Don't go there, please.
-
Hi Andre,
Would you please add in some more inputs or a source link - for not using a thread to run a timer?
-
[quote author="veeraps" date="1334824358"]Hi Andre,
Would you please add in some more inputs or a source link - for not using a thread to run a timer?[/quote]
Sure, "here":/wiki/Threads_Events_QObjects#92dd35cc61ffc41d02defdcef071856d you go. -
Thanks Andre for the information - learnt a new thing today.