[英]QT5 Signals does not activate the functions inside SLOT
大家早上好,感谢您的宝贵时间。
我创建了一个魔方程序,我想将它与串行链接 controller 连接。一切正常且独立,但是当我将线程(串行连接)连接到程序的 rest 时,它不起作用。
我创建了一个调用立方体旋转 function 的信号。 该信号被调用并且它很好地调用了函数但它不会改变内部的值,这就像创建我的 class 的新实例而不直接修改它。 代码调用得很好,但我在 qwidget 中的显示没有改变。 这是我的代码的一部分,感谢您的帮助:对不起我的英语我来自法国:)
立方体.h:
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();
};
我的信号在Cube function中的定义:
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();
......
我的 main.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 *lecture
和Cube c
是两个不同的对象。 你的意思是以下吗?
QObject::connect(lecture, &Cube::MySignal, &c, &Cube::rotationFComplete);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.