在QRunnable的子类MyRunnable中,怎样编写一个signal,使得这个signal与QTextBrowser的append方法连接?
我写了一个,老是说,我的connect不匹配,求教啊!
#ifndef MYRUNNABLE_H
#define MYRUNNABLE_H
#include <QRunnable>
#include <QTcpSocket>
#include <QTextBrowser>
#include <QtCore>
class MyRunnable : public QRunnable
{
Q_OBJECT
public:
explicit MyRunnable(QObject *parent = 0);
int SocketDescriptor;
void Initial(QTextBrowser*,int);
QTextBrowser *text;
QTcpSocket *socket;
protected:
void run();
void Login();
void TimeLink();
void SendMessage();
void SiPin();
signals:
void UpdateUi(QString);
public slots:
};
#endif // MYRUNNABLE_H
#include "myrunnable.h"
MyRunnable::MyRunnable(QObject *parent) :
QRunnable()
{
}
void MyRunnable::Initial(QTextBrowser *text,int SocketDescriptor )
{
this->text=text;
this->SocketDescriptor=SocketDescriptor;
connect(this,SIGNAL(UpdateUi(QString)),text,SLOT(append(QString)));
}
void MyRunnable::run()
{
if(!SocketDescriptor){
qDebug()<<"!sock";
return;
}
else{
QTcpSocket socket;
socket.setSocketDescriptor(SocketDescriptor);
qDebug()<<"****************************\n";
// text->append("****************************");
// text->append("User:"+QString::number(SocketDescriptor));
// socket.r
//qDebug()<<socket.readAll();
// socket.waitForReadyRead(3000);
//text->append(socket.readAll());
// text->append("****************************\n");
// socket.write("aaaaaaaaaaaaaaaaaaaaaaaaa");
emit UpdateUi("*************************");
emit UpdateUi("User:"+QString::number(SocketDescriptor));
socket.waitForReadyRead(3000);
// emit UpdateUi("User:"+QString::number(SocketDescriptor));
emit UpdateUi(socket.readAll());
emit UpdateUi("*************************");
socket.close();
}
}
报以下错误:
..\MyServer\myrunnable.cpp:3:1: warning: unused parameter 'parent' [-Wunused-parameter]
..\MyServer\myrunnable.cpp: In member function 'void MyRunnable::Initial(QTextBrowser*, int)':
..\MyServer\myrunnable.cpp:12:70: error: invalid conversion from 'MyRunnable* const' to 'SOCKET {aka unsigned int}' [-fpermissive]
..\MyServer\myrunnable.cpp:12:70: error: cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int connect(SOCKET, const sockaddr*, int)'
求教啊