16,175
社区成员
发帖
与我相关
我的任务
分享
class MyThread : public QThread
{
Q_OBJECT
public:
//explicit MyThread(QObject *parent = 0);
~MyThread();
public:
MyThread();
protected:
void run();
private:
widgetSec *myptr;
QTcpSocket *ThreadTcp;
public:
QString a;
QTcpSocket *tcp;
int TcpDes;
signals:
void threadEnd();
void deliverInfo();//传递信号
public slots:
};
MyThread::MyThread()
{
connect(this,SIGNAL(finished()),this,SLOT(deleteLater()));
}
MyThread::~MyThread()
{
delete ThreadTcp;我在析构函数中加delete ,信息就会发不出去
}
void MyThread::run()
{//while(1){
ThreadTcp=new QTcpSocket;
ThreadTcp->setSocketDescriptor(TcpDes);
int sign=ThreadTcp->write(a.toLatin1());
qDebug()<<sign;
ThreadTcp->waitForBytesWritten(-1);
bool b=ThreadTcp->flush();
}