QT多线程sign/slots问题

csprimer 2010-01-06 02:34:48
在新线程里QTime和http请求不能用sign/slots机制,请问大家该怎么实现
1.
void newThread::run()
{

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(downloadReadyRead()));
timer->start(5000);



}
void newThread::downloadReadyRead()
{

}

无法触发slot
2.
QUrl url("http://localhost/Default.aspx");
QNetworkRequest request(url);
currentDownload = manager.get(request);
connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
SLOT(downloadProgress(qint64,qint64)));
connect(currentDownload, SIGNAL(finished()),this,
SLOT(downloadFinished()));
connect(currentDownload, SIGNAL(readyRead()),this,
SLOT(downloadReadyRead()));
新线程里也无法触发slot,qt的线程机制有点没看懂,请大家帮忙
...全文
158 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
csprimer 2010-01-06
  • 打赏
  • 举报
回复
谢谢了,好了,其实我昨天就加exec了,就是没搞弄好,今天一下就好了,还是得多看看原理啊。想想也应该在新的线程用connect,要不然就太麻烦了。
zhu_xz 2010-01-06
  • 打赏
  • 举报
回复
你的run结束后,新的thread也就结束了,自然无法接受slot了啊
在run的最后调用exec函数,开始监听该thread上的事件

此外,关于slot何时被触发,可以看看这个文档:
http://qt.nokia.com/doc/4.6/qt.html#ConnectionType-enum

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧