简体   繁体   中英

QT5 Signals does not activate the functions inside SLOT

Good morning everyone and thank you for your time.

I have created a rubik's cube program and I would like to connect it with a serial link controller.Everything works fine and independently but when I connect my thread (serial connection) to the rest of the program it doesn't work.

I have created a signal that calls a cube rotation function. The signal is called and it calls the functions well but it doesn't change the values inside, it's like creating a new instance of my class without directly modifying it. The code is called well but my display in the qwidget doesn't change. Here is a part of my code, thanks for your help: Sorry for my english I come from France :)

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

The definition of my signal in Cube function:

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

Where i emit the signal:

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

My 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 and Cube c are two different objects. Did you mean to the following?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM