Qt4子线程在主线程上编辑Gui
我有一个表格小部件,需要附加来自子线程的数据。
我收到此错误在 GUI 线程之外使用像素图是不安全的。在 C# 中,我使用 Dispatcher 告诉 mainThread 将数据附加到 gui 对象中。
我想有一些与此接近的东西吗?我使用qt4.7 我在父线程中创建了一个槽,并在线程对象中创建了一个信号。子线程发出信号,将信号发送到父线程中的槽。但信号没有发射。当我执行像这样的方法时 object->run(); (即从主线程)它工作正常..但是当我从线程对象执行它时 - > start();信号未触发..我需要对不在主线程中的线程做一些工作..
更新--27/09 我刚刚找到问题的根源..信号和插槽正在工作,但子线程正在启动一个导致所有这些麻烦的 qnetworkaccessmanger 对象..我评论了网络访问对象并且没有错误..我需要线程来调用网络请求..并更新 GUI 中的结果..
I have a tablewidget which needs to be appended with data from a child thread.
I get this error It is not safe to use pixmaps outside the GUI thread. In c# I used a Disptacher to tell the mainThread to append data in a gui object.
I assume there is some how something close to this? Am using qt4.7
I have made a slot in the parent and a signal within the thread object.. an emit signal from the child thread to send a signal to a slot in the parent. but the signal is not firing. when i execute the method like so object->run(); (i.e from mainthread) it works fine.. but when i execute it from the thread object->start(); the signal is not fired.. i neeed to do somework with a thread not in mainthread..
UPDATE--27/09
i just got to the root of the problem.. the signal and slot are working but the child thread is lauching a qnetworkaccessmanger object that is causing all this trouble.. i commented the networkaccess object and no error.. I need the thread to call a network request.. and update the results in the gui..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是使用 Qt 的信号/槽机制,连接类型为 < a href="http://doc.qt.nokia.com/latest/qt.html#ConnectionType-enum" rel="nofollow">Qt::QueuedConnection。这会自动对接收者对象所在线程中的槽的调用进行排队。
The easiest way is to use Qt's signal/slot mechanism with a connection type of Qt::QueuedConnection. This queues the call to the slot in the thread the receiver object lives in automatically.