QT5信号未激活SLOT内部的功能

问题描述 投票:0回答:1

大家早上好,谢谢您的时间。

我创建了一个rubik的多维数据集程序,我想将其与串行链接控制器连接。一切正常且独立运行,但是当我将线程(串行连接)连接到程序的其余部分时,它将无法正常工作。] >

我创建了一个调用多维数据集旋转功能的信号。信号被调用并且可以很好地调用函数,但是它不会更改内部的值,就像在不直接修改它的情况下创建类的新实例一样。该代码调用得很好,但是我在qwidget中的显示未更改。这是我的代码的一部分,感谢您的帮助!对不起,我的英语是我来自法国:)

cube.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函数中我的信号的定义:

    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();
}
    

大家早上好,感谢您的宝贵时间。我创建了一个rubik的多维数据集程序,并希望将其与串行链接控制器连接。一切正常且独立运行,但是当...

c++ multithreading qt signals slot
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.