![]() ![]() Then create a new QThread instance, push the QObject onto it using moveToThread(QThread*) of the QObject instance and call start() on the QThread instance. A QThread should be used much like a regular thread instance: prepare an object (QObject) class with all your desired functionality in it. This should immediately show why the recommended way of using QThreads in the documentation, namely to sub-class it and implement your own run() function, is very wrong. This wrapper provides the signals, slots and methods to easily use the thread object within a Qt project. The main thing to keep in mind when using a QThread is that it’s not a thread. Right because QThreads are in fact quite easy to use, as long as you ignore the incorrect official Qt documentation on QThread and the myriad of wrongful methods being employed. Wrong because years of wrong documentation from Trolltech/Nokia on QThread has caused countless people to use QThreads in a convoluted and highly inappropriate manner. Those who have discovered the joys of the Qt framework may assume that threads in Qt (QThread) are just like this, but they would be both wrong and right. I’d venture to say that they’re at least a lot easier to use and handle than sockets □ Whether it are Win32, POSIX or other threads, they all basically work the same and are quite fool-proof. Use a mutex or other method to safely communicate with the thread if necessary. Write a function, maybe bundle it with some data and push it onto a newly created thread. Threads in an operating system are a very simple thing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |