promoted widget & custom class ... not work everytime at same manner



  • These is a led custom widget .... I have 12 colour of led on my app ..qrectledo for orange, qrectledv for green, qrectledb for blue etc etc... the internal variable & void of class every class have different name, ex: RLBexchange for exchange blue led, RLVexchange for exchange green led etc etc .... so not a problem of "names" .... obviously I use more than one led widget "blue" for example.

    /* ************  my qrectledb.h file ************************/
    #ifndef QRECTLEDB_H
    #define QRECTLEDB_H
    
    #include <QLabel>
    #include <QPixmap>
    #include <QTimer>
    
    class QRectLedb : public QLabel
    {
        Q_OBJECT
    public:
        QRectLedb(QWidget *parent = 0);
    public slots:
    
        void RLBexchange(bool Rlb);
    
    private slots:
    
        void RBon();
        void RBoff();
    
    
    private:
        QPixmap onPixmap, offPixmap;
    
    };
    
    #endif // QRECTLEDV_H
    
    
    /* ************  my qrectledb.cpp file ************************/
    
    
    #include "qrectledb.h"
    
    QRectLedb::QRectLedb(QWidget *parent)
        : QLabel(parent), onPixmap("/home/C/res/rect_led_blue_on_130.png"), offPixmap("/home/C/res/rect_led_blue_off_130.png")
    {
        setPixmap(offPixmap);
    
    
    }
    
    void QRectLedb::RLBexchange(bool Rlb)
    {
        if (Rlb == true) { RBon();} else {RBoff();};
    }
    
    void QRectLedb::RBoff()
    {
        setPixmap(offPixmap);
    }
    
    void QRectLedb::RBon()
    {
        setPixmap(onPixmap);
    }
    
    
    /****************** on my mainwindows  command for led ***********************/
    
    void MainWindow::vst_is_on_1(bool st_on_1){if(st_on_1){ui->rledb_on_1->RLBexchange(true); }else{ui->rledb_on_1->RLBexchange(false); }}
    void MainWindow::vst_is_on_2(bool st_on_2){if(st_on_2){ui->rledb_on_2->RLBexchange(true); }else{ui->rledb_on_2->RLBexchange(false); }}
    void MainWindow::vst_is_on_3(bool st_on_3){if(st_on_3){ui->rledb_on_3->RLBexchange(true); }else{ui->rledb_on_3->RLBexchange(false); }}
    

    these is on my mainwindows ... vst_is_on_1/2/3 is call from QThread in the same manner but only vst_is_on_3 works fine ... vst_is_on_2 not work and vst_is_on_1 works only sometime ....

    Is possible the problem become because all the graphical gui part is build with QTcreator and these class insert an image with online code?? Or is because I make bad use of API? (or the problem is in some other place of my app?? )

    Anyone see something of wrong in my code?

    regards
    Giorgio



  • @gfxx so no one see any problem in that code .... ok. I control again my mainwindows vst_is_on call ...

    giorgio


  • Qt Champions 2016

    @gfxx
    Hi using promotion in Creator cannot change how it works.
    It will merely replace the Type of the class in the generated code.
    So you are looking for something else.

    Regarding issues
    You are using paths to your images
    "/home/C/res/rect_led_blue_on_130.png"
    That will break as soon as you run app on other computer.

    You should use a qres file for those images
    http://doc.qt.io/qt-5/resources.html

    Use the debugger and see if the slots are called.

    Make sure you are using QueuedConnection on the connects if u emit on/off signal from other thread.

    Also
    You are only using RLBexchange in all vst_is_on_1 -> vst_is_on_3
    This is correct.
    Asking as you said you have RLVexchange and so on but code dont show them.



  • @mrjj said in promoted widget & custom class ... not work everytime at same manner:

    Regarding issues
    You are using paths to your images
    "/home/C/res/rect_led_blue_on_130.png"
    That will break as soon as you run app on other computer.

    Thanks I know these ... and I have qres file in my app ... sorry but some part of code is reused from other one (when not I use qres yet!). For shure I adjust these ... I use only Queuedconnection because is only an advice signal not command one ... so not need these.

    At these point for sure the problem become from my thread that read the signal from external world ... the connection with extern world is ok ... verified with wireshark .... so the problem is located onto qthread that read the external signal.

    Thanks a lot for these confirm.

    regards
    giorgio


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.