先贴一段代码:(checkThread、myThread是我自己创建的线程)
checkThread *ckthread = new checkThread;
connect(ckthread, SIGNAL(notifymain(QString)), this, SLOT(testwjz(QString)));
ckthread->start();
myThread *bundlthread = new myThread;
bundlthread->start();
两个线程我都重写了他们的run函数。
void checkThread::run()
{
while(true)
{
sleep(3);
emit notifymain("This is the son thread");
}
exec();
}
void MainWindow::testwjz(QString s)
{
qDebug()<<s;
}
问题估计出在第二个线程:我先这样重写它的run函数的。
void myThread::run()
{
while(true)
{
qDebug()<<"Thread is running!";
sleep(3);
}
exec();
}
程序运行正常。
然后我改了一下:
void myThread::run()
{
BundlerApp::RunBundler();//调用了一个算法
exec();
}
然后出现错误
"This is the son thread"
"This is the son thread"
线程 'Win32 线程' (0x143c) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x2ad4) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x2054) 已退出,返回值为 0 (0x0)。
线程 'checkThread' (0x2868) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x1c54) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x2a14) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0xbe8) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x1e60) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x2698) 已退出,返回值为 0 (0x0)。
线程 'Win32 线程' (0x2aa4) 已退出,返回值为 0 (0x0)。
Detected memory leaks!
Dumping objects ->
{943782} normal block at 0x12010768, 11 bytes long.
Data: < > 01 01 01 01 00 01 00 01 01 01 01
{943775} normal block at 0x12044D38, 336 bytes long.
Data: < r d i > B4 01 00 00 72 01 00 00 64 02 00 00 69 01 00 00
{943771} normal block at 0x12046710, 336 bytes long.
Data: <r i d > 72 01 00 00 B4 01 00 00 69 01 00 00 64 02 00 00
{943737} normal block at 0x12045C18, 752 bytes long.
Data: < 8 d > B4 01 00 00 38 01 00 00 64 02 00 00 A1 01 00 00
{943733} normal block at 0x120491F8, 752 bytes long.
Data: <8 d > 38 01 00 00 B4 01 00 00 A1 01 00 00 64 02 00 00
{943333} normal block at 0x12050FA0, 1128 bytes long.
Data: < 3 b > B7 00 00 00 F8 00 00 00 33 01 00 00 62 01 00 00
{943329} normal block at 0x12047C70, 1128 bytes long.
Data: < b 3 > F8 00 00 00 B7 00 00 00 62 01 00 00 33 01 00 00
{943229} normal block at 0x12012180, 1128 bytes long.
Data: < 3 a > B7 00 00 00 F2 00 00 00 33 01 00 00 61 01 00 00
{943120} normal block at 0x12044890, 1128 bytes long.
Data: <r 0 w : > 72 01 00 00 30 01 00 00 77 01 00 00 3A 01 00 00
{943116} normal block at 0x12050AF8, 1128 bytes long.
Data: <0 r : w > 30 01 00 00 72 01 00 00 3A 01 00 00 77 01 00 00
{942938} normal block at 0x1204EA00, 752 bytes long.
Data: <r w < > 72 01 00 00 03 01 00 00 77 01 00 00 3C 02 00 00
{942706} normal block at 0x12048350, 1688 bytes long.
Data: < > AD 00 00 00 B0 00 00 00 F8 00 00 00 F2 00 00 00
{942474} normal block at 0x12050420, 1688 bytes long.
Data: < > EB 00 00 00 A6 00 00 00 F3 00 00 00 B1 00 00 00