QT中想在子线程中python 创建子线程对话窗口怎么建

2013年2月 移动平台大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。用户名:FinderCheng
文章数:123
评论数:1068
访问量:5296442
注册日期:
阅读量:1297
阅读量:3317
阅读量:440649
阅读量:1127148
51CTO推荐博文
接着前一篇,下面是源代码部分:
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />#include &QtGui& 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />#include "finddialog.h" 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />FindDialog::FindDialog(QWidget *parent) 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&: QDialog(parent) 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />{ 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&label = new QLabel(tr("Find &what:")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&lineEdit = new QLineE 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&label-&setBuddy(lineEdit); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&caseCheckBox = new QCheckBox(tr("Match &case")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&backwardCheckBox = new QCheckBox(tr("Search &backford")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&findButton = new QPushButton(tr("&Find")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&findButton-&setDefault(true); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&findButton-&setEnabled(false); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&closeButton = new QPushButton(tr("Close")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(enableFindButton(const QString&))); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QHBoxLayout *topLeftLayout = new QHBoxL 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&topLeftLayout-&addWidget(label); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&topLeftLayout-&addWidget(lineEdit); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QVBoxLayout *leftLayout = new QVBoxL 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&leftLayout-&addLayout(topLeftLayout); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&leftLayout-&addWidget(caseCheckBox); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&leftLayout-&addWidget(backwardCheckBox); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QVBoxLayout *rightLayout = new QVBoxL 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&rightLayout-&addWidget(findButton); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&rightLayout-&addWidget(closeButton); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&rightLayout-&addStretch(); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QHBoxLayout *mainLayout = new QHBoxL 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&mainLayout-&addLayout(leftLayout); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&mainLayout-&addLayout(rightLayout); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&setLayout(mainLayout); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&setWindowTitle(tr("Find")); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&setFixedHeight(sizeHint().height()); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />} 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />FindDialog::~FindDialog() 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />{ 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />} 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />void FindDialog::findClicked() 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />{ 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QString text = lineEdit-&text(); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&Qt::CaseSensitivity cs = caseCheckBox-&isChecked() ? Qt::CaseInsensitive : Qt::CaseS 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&if(backwardCheckBox-&isChecked()) { 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&&&&&&&&&emit findPrevious(text, cs); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&} else { 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&&&&&&&&&emit findNext(text, cs); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&} 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />} 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />void FindDialog::enableFindButton(const QString &text) 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />{ 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&findButton-&setEnabled(!text.isEmpty()); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />}
&CPP文件要长一些哦――不过,它们的价钱也会更高,嘿嘿――嗯,来看代码,第一行include的是QtGui。Qt是分模块的,记得我们建工程的时候就会问你,使用哪些模块?QtCore?QtGui?QtXml?等等。这里,我们引入QtGui,它包括了QtCore和QtGui模块。不过,这并不是最好的做法,因为QtGui文件很大,包括了GUI的所有组件,但是很多组件我们根本是用不到的――就像Swing的import,你可以import到类,也可以使用*,不过都不会建议使用*,这里也是一样的。我们最好只引入需要的组件。不过,那样会把文件变长,现在就先用QtGui啦,只要记得正式开发时不能这么用就好啦!
构造函数有参数初始化列表,用来调用父类的构造函数,相当于Java里面的super()函数。这是C++的相关知识,不是Qt发明的,这里不再赘述。
然后新建一个QLabel。还记得前面的Hello, world!里面也使用过QLabel吗?那时候只是简单的传入一个字符串啊!这里怎么是一个函数tr()?函数tr()全名是QObject::tr(),被它处理的字符串可以使用工具提取出来翻译成其他语言,也就是做国际化使用。这以后还会仔细讲解,只要记住,Qt的最佳实践:如果你想让你的程序国际化的话,那么,所有用户可见的字符串都要使用QObject::tr()!但是,为什么我们没有写QObject::tr(),而仅仅是tr()呢?原来,tr()函数是定义在Object里面的,所有使用了Q_OBJECT宏的类都自动具有tr()函数。
字符串中的&代表快捷键。注意看下面的findButton的&Find,它会生成Find字符串,当你按下Alt+F的时候,这个按钮就相当于被点击――这么说很难受,相信大家都明白什么意思。同样,前面label里面也有一个&,因此它的快捷键就是Alt+W。不过,这个label使用了setBuddy函数,它的意思是,当label获得焦点时,比如按下Alt+W,它的焦点会自动传给它的buddy,也就是lineEdit。看,这就是伙伴的含义(buddy英文就是伙伴的意思)。
后面几行就比较简单了:创建了两个QCheckBox,把默认的按钮设为findButton,把findButton设为不可用――也就是变成灰色的了。
再下面是三个connect语句,用来连接信号槽。可以看到,当lineEdit发出textChanged(const QString&)信号时,FindDialog的enableFindButton(const QString&)函数会被调用――这就是回调,是有系统自动调用,而不是你去调用――当findButton发出clicked()信号时,FindDialog的findClicked()函数会被调用;当closeButton发出clicked()信号时,FindDialog的close()函数会被调用。注意,connect()函数也是QObject的,因为我们继承了QObject,所以能够直接使用。
后面的很多行语句都是layout的使用,虽然很复杂,但是很清晰――编写layout布局最重要一点就是思路清楚,想清楚哪个套哪个,就会很好编写。这里我们的对话框实际上是这个样子的:
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
border="0" alt="" src="/attachment/063421.png" />
注意那个spacer是由rightLayout的addStretch()添加的,就像弹簧一样,把上面的组件“顶起来”。
最后的setWindowTitle()就是设置对话框的标题,而setFixedHeight()是设置成固定的高度,其参数值sizeHint()返回“最理想”的大小,这里我们使用的是height()函数去到“最理想”的高度。
好了,下面该编写槽了――虽然说是slot,但实际上它就是普通的函数,既可以和其他函数一样使用,又可以被系统回调。
先看findClicked()函数。首先取出lineEdit的输入值;然后判断caseCheckBox是不是选中,如果选中就返回Qt::CaseInsensitive,否则返回Qt::CaseSensitive,用于判断是不是大小写敏感的查找;最后,如果backwardCheckBox被选中,就emit(发出)信号findPrevious(),否则emit信号findNext。
enableFindButton()则根据lineEdit的内容是不是变化――这是我们的connect连接的――来设置findButton是不是可以使用,这个很简单,不再说了。
这样,FindDialog.cpp也就完成了。下面编写main.cpp――其实QtCreator已经替我们完成了――
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />#include &QApplication& 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />#include "finddialog.h" 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" /> 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />int main(int argc, char *argv[]) 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />{ 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&QApplication app(argc, argv); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&FindDialog *dialog = new FindD 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&dialog-&show(); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />&&&&&&&&return app.exec(); 650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)'
align="top" src="http://jbean./images/editer/InBlock.gif" />}
运行一下看看我们的成果吧!
虽然很简单,也没有什么实质性的功能,但是我们已经能够制作对话框了――Qt的组件成百上千,不可能全部介绍完,只能用到什么学什么,更重要的是,我们已经了解了其编写思路,否则的话,即便是你拿着全世界所有的砖瓦,没有设计图纸,你也不知道怎么把它们组合成高楼大厦啊!
嘿嘿,下回见!本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)
本文收录至博客专题:《》
23:43:34 18:52:09 15:45:48 16:24:09 16:26:10 17:39:22 11:05:24 20:48:09 10:36:01 08:51:15 08:05:01 21:41:28 22:07:48 15:45:25 14:55:37 23:28:27 13:12:18 20:21:36 20:26:34 22:03:44 &&1&
&&页数 ( 1/2 ) &您所在的位置: &
Qt开发:释放线程中创建的QUdpSocket对象
Qt开发:释放线程中创建的QUdpSocket对象
在做Symbian应用开发和MeeGo应用开发时Q框架是一个统一的开发框架,很多时候需要在QThread的run中new一个QUdpSocket来收发数据.这时,这个socket对象的释放就成了一个麻烦的问题.
51CTO编者按:在做和MeeGo应用开发时Q框架是一个统一的开发框架,很多时候需要在QThread的run中new一个QUdpSocket来收发数据.这时,这个socket对象的释放就成了一个麻烦的问题.
如果在thread的析构中直接delete这个socket对象,则会出现如下异常:
QSocketNotifier:&socket&notifiers&cannot&be&disabled&from&another&thread&&ASSERT&failure&in&QCoreApplication::sendEvent:&&Cannot&send&events&to&objects&owned&by&a&different&thread.&Current&thread&560cb8.&Receiver&&&(of&type&&QNativeSocketEngine&)&was&created&in&thread&a617748&P,&file&kernel\qcoreapplication.cpp,&line&349&Invalid&parameter&passed&to&C&runtime&function.&Invalid&parameter&passed&to&C&runtime&function.&
以下是解决方案:
◆在线程中定义一个线程释放的标识
◆在run()中用while来判断这个标识,以便于结束socket对象.
◆在thread的析构中,设定标识,并使用quit()和wait().
UdpSocketThread::UdpSocketThread(QObject&*parent)&:&&QThread(parent)&{&this-socket&=&0;&this-needStop&=&false;&}&&UdpSocketThread::~UdpSocketThread()&{&this-needStop&=&true;&quit();&wait();&}&&void&UdpSocketThread::run()&{&socket&=&new&QUdpS&connect(socket,SIGNAL(readyRead()),this,SLOT(readPendingDatagrams()));&socket-bind(2234);&exec();&while(this-needStop)&{&if(this-socket)&{&delete&this-&this-socket&=&0;&}&&}&}&
这个线程对象的释放比较有代表性,应该可以解决很多类似的问题.
另外,方法可能还有其他的,这里只是举了一种而已.
其实,问题的关键就是:线程中创建的对象就必须在线程中释放.
经shiroki的指正,其实QT有更好的机制来释放对象.那就是deleteLater(). 于是,事情就显得非常简单,请看代码:
UdpSocketThread::UdpSocketThread(QObject&*parent)&:&&QThread(parent)&{&socket&=&0;&}&&UdpSocketThread::~UdpSocketThread()&{&this-socket-deleteLater();&quit();&wait();&}&&void&UdpSocketThread::run()&{&socket&=&new&QUdpS&connect(socket,SIGNAL(readyRead()),this,SLOT(readPendingDatagrams()));&socket-bind(2234);&exec();&&}&
活动日期:1月15日
本期主题:Android应用开发技术进阶
地点:北京市海淀区中关村南大街30号东联艺术工社
演讲讲师:范怀宇(网易)
【编辑推荐】
【责任编辑: TEL:(010)】
关于&&的更多文章
本专题为Qt编程基础入门。Qt是诺基亚开发的一个跨平台的C++图形
在经过数月以及6个测试版本的体验后,iOS 7正式版终于
微软的思路很明确。一个消费者需要拥有几款电子设备?
中秋已过,圆圆的月亮似乎是一个害羞的姑娘,带上了一
本书以Linux Redhat 9.0中文版为基础编写,从易用性和实用性角度出发主要介绍Linux Redhat 9.0中文版的应用知识,通过本书的学习
Windows Phone专家
Android开发专家
51CTO旗下网站QT中想在子线程中创建对话窗口怎么建?【qt吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:33,033贴子:
QT中想在子线程中创建对话窗口怎么建?收藏
其实就是在主线程中建立一个子线程,然后在子线程中new一个dialog,在dialog中建立对话,但是问题出现,如果在子线程中新建dialog,会出现对gui操作只能在主线程中执行的错误:ASSERT failure in QWidget: "Widgets must be created in the GUI thread.", file kernel\qwidget.cpp, line 1264所以想问如何在子线程创建dialog,然后对dialog进行操作
求指教!!!我源代码是这么写的:下面是在线程中写的代码:emit 是发了一个信号,我想用一个线程建一个chatDlg,这样就能建多个chatdlg聊天了,可以互不干扰。然后在主线程写了一个函数槽信号:
将上面那个dlg传给了主线程,希望show它
最后是newDlog函数:请问问题在哪????
怎么实现多人聊天呢?
据说,Qt的GUI类,尤其是QWidget及其子类不可重入。PS:多人聊天又没必要用多线程,多个窗口又不会造成事件堵塞,用signal&slot就可以了。
我知道了,谢了啊。那在主线程建dialog,然后在dialog中建线程。如此可行吗?
反正就一个原则:涉及到界面修改的部分,必须在UI线程中进行。记下来!
的方式是 最好的。
废话太多了
登录百度帐号推荐应用}

我要回帖

更多关于 java创建子线程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信