QT5 信号不会激活插槽内的功能

QT5 Signals does not activate the functions inside SLOT

本文关键字:功能 插槽 激活 信号 QT5      更新时间:2023-10-16

大家早上好,谢谢大家抽出宝贵时间。

我已经创建了一个魔方程序,我想将其与串行链路控制器连接。一切都工作正常且独立,但是当我将线程(串行连接(连接到程序的其余部分时,它不起作用。

我创建了一个调用立方体旋转函数的信号。信号被调用并且它很好地调用了函数,但它不会更改内部的值,就像创建我的类的新实例而不直接修改它一样。 代码调用得很好,但我在 qwidget 中的显示没有改变。 这是我代码的一部分,感谢您的帮助!对不起,我的英语我来自法国:)

立方体 :

class Cube : public QWidget {
Q_OBJECT
private:
int w[3][3];
int o[3][3];
int v[3][3];
int r[3][3];
int b[3][3];
int j[3][3];
int wPerma[3][3];
int oPerma[3][3];
int vPerma[3][3];
int rPerma[3][3];
int bPerma[3][3];
int jPerma[3][3];
public:
QWidget Fenetre;
QString str;
QGridLayout *gridLayout = new QGridLayout(&Fenetre);
Cube();
.......
public slots:
void rotationFComplete();
void rotationBComplete();
void rotationUComplete();
void rotationDComplete();
void rotationLComplete();
void rotationRComplete();
void rotationFpComplete();
void rotationBpComplete();
void rotationUpComplete();
void rotationDpComplete();
void rotationLpComplete();
void rotationRpComplete();
void melangeCube();
void resetCube();signals:
void MySignal( void );
};

class serial : public Cube {
public:
int Port();
};

我的信号在立方体函数中的定义:

QObject::connect(this, SIGNAL(MySignal()), this, SLOT(rotationFComplete()));

我发出信号的地方:

int serial::Port()
{
// Serial object
SerialPortManager serial;
unsigned char buffer[128]="";
int ret = 0;
bool State1 = false,
State2 = false,
State3 = false,
State4 = false,
State5 = false,
State6 = false,
State7 = false,
State8 = false,
State9 = false,
State10 = false,
State11 = false,
State12 = false,
State13 = false,
State14 = false,
State15 = false,
State16 = false;
int Octet1,Octet2;
QString temp;
emit MySignal();
......

我的主要.cpp :

int main(int argc, char *argv[]){
QApplication app(argc, argv);
serial* lecture = new serial();
Cube c;
c.affichage2d();
thread th(&serial::Port, lecture);
c.Fenetre.show();

return app.exec();
}

serial *lectureCube c是两个不同的对象。你的意思是以下吗?

QObject::connect(lecture, &Cube::MySignal, &c, &Cube::rotationFComplete);