Здравствуйте! Проблема в том, что не срабатывают слоты в вызываемые из обьекта класса QThread,который создаётся в свою очередь в QWidget. Вот класс QWidget:
| Код | class Rumus : public QWidget { Q_OBJECT
public: Rumus(QWidget *parent = 0, Qt::WFlags flags = 0); ~Rumus();
private: Ui::RumusClass ui; authRumus1 *auth1;
public: QTextEdit *tedit;
};
|
Его конструктор:
| Код | Rumus::Rumus(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) { ui.setupUi(this); tedit=qFindChild<QTextEdit*>(this,"textEdit"); auth1= new authRumus1(this); connect(auth1,SIGNAL(readBuff(const QString &)),tedit,SLOT(insertPlainText(const QString &))); auth1->start(); //Запускается поток tedit->setText("Test\n"); }
|
Класс потока:
| Код | class authRumus1 : public QThread { Q_OBJECT
public: authRumus1(QObject *parent); ~authRumus1(); QTcpSocket *socket; unsigned char buff[255];
protected: void run(); signals: void readBuff(const QString &); //не срабатывает
public slots: void ReadData(); // не срабатывает void errorRead(QAbstractSocket::SocketError socketError); void sockcon(){ //не срабатывает, хотя сокет подключается emit readBuff("Socket Connected!\n"); QMessageBox::information(0,"Socket","Connection!"); } };
|
Конструктор QTheart:
| Код | authRumus1::authRumus1(QObject *parent) : QThread(parent) { socket= new QTcpSocket(this); connect(socket,SIGNAL(readyRead()),this,SLOT(ReadData())); connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorRead(QAbstractSocket::SocketError))); connect(socket,SIGNAL(connected()),this,SLOT(sockcon())); emit readBuff("constr"); //сигнал не обрабатывается
}
|
В методе Run сокет подключается к серверу и сигнал readBuff вполне работает. |