multithreading - Qt: Using thread to construct widgets -
In my application, I have a QWidget MyWidget
, which I want to create after push button clicks is required. Now, MyWijet is a heavy widget with many children's components and there are many components of those children's components. Now, when I try to create a widget after pressing the push button, it can sometimes be used for widgets. I do not like, which I do not like Therefore, I have to build the widget before clicking pushbutan and put an example on hand. Thread looks right for this job. But I have very little information about QT threads.
Now someone can suggest me how to deal with the problem and what can be done to solve this problem?
Note: To say clearly why my widget is so heavy, in MyWdtate, I have 7 * 24 widgets, each containing a stacked widget that has two widgets containing each button. .
QT does not support the creation of widgets in non-gui threads. The reason is simple: Widget Consultants Threads-free to access to unsafe APIs that can be used by the main thread at any time. Even if this may seem to work, it is actually a bug in your code if you do this.
Generally, parallel non-graphical, long-running initial tasks in their heavyweight widget classes. You can use QtConcurrent :: run
for this purpose, of course, you need to make your implementation thread-safe for this purpose.
You should also make sure that you use any blocked API in your widget code, absolutely, not positively. There is usually no GUI code, but a widget constructor should never be specifically:
-
Wait for any file access to finish,
-
Wait
-
any
waitForXxxx
-
-
< / Li>
-
-
Code> Methods in QT.
Comments
Post a Comment