Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect Custon Widget with MainWindow
Forum Updated to NodeBB v4.3 + New Features

Connect Custon Widget with MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raulgg
    wrote on last edited by
    #1

    Hi people, I made this question in the Spanish section, but I need more feedbak...

    I'm working in an application, I have several custom widgets and they are showing in the MainWindow's Central Widget. The child widget made one check and it must send the result to Statusbar in the Mainwindow. I'm trying with SIGNAL and SLOTS, but I loss...

    The code:

    inicio.h

    public slots:
        void changeconexionstatus(const bool &statuscon);
    

    inicio.cpp

    void inicio::terminal(){
       prueba *open = new prueba(this);
       connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus);
       this->setCentralWidget(open);
    }
    
    void inicio::changeconexionstatus (const bool &statuscon){
        if (statuscon){
            statusconico->setPixmap(QPixmap(":/img/img/connect.png"));
        }
    }
    

    prueba.h

    signals:
        void statusconexion(const bool &value);
    

    prueba.cpp

    connect(ui->pushButton,&QPushButton::clicked,this,check_connection);
    
    void tpv::check_connection(){
            emit statusconexion(true);
    }
    

    With this code if I clicked the button the SIGNAL is emitted, but I need that the SIGNAL is sent when the function check_conection finish run... If I call directly to the function the SIGNAL is not emitted.

    Thanks in advance

    Regards
    Raul

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From your description, it seems that you should call emit at the end of check_connection. So it's not really clear what your problem is.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raulgg
        wrote on last edited by
        #3

        I think that I know where is my problem... but I don't know who I can solve for the moment :-(.

        I think that the problem is in the run time line.... when tpv *open = new tpv(this) the custom widget is load and the check_connection emit the signal but the connection in the main window connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus); is not active yet and then nothing change in the Mainwindow.

        For this reason when I send signal with a pushbutton in the custom widget it work, because the custom widget is loaded completely and the connection in the main window created.

        jsulmJ 1 Reply Last reply
        0
        • R raulgg

          I think that I know where is my problem... but I don't know who I can solve for the moment :-(.

          I think that the problem is in the run time line.... when tpv *open = new tpv(this) the custom widget is load and the check_connection emit the signal but the connection in the main window connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus); is not active yet and then nothing change in the Mainwindow.

          For this reason when I send signal with a pushbutton in the custom widget it work, because the custom widget is loaded completely and the connection in the main window created.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @raulgg Do you mean you call check_connection() in the tpv constructor?
          If so, then you can simply remove that call from constructor and call it outside:

          tpv *open = new tpv(this);
          connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus);
          open->check_connection();
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          3
          • jsulmJ jsulm

            @raulgg Do you mean you call check_connection() in the tpv constructor?
            If so, then you can simply remove that call from constructor and call it outside:

            tpv *open = new tpv(this);
            connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus);
            open->check_connection();
            
            R Offline
            R Offline
            raulgg
            wrote on last edited by
            #5

            @jsulm said in Connect Custon Widget with MainWindow:

            @raulgg Do you mean you call check_connection() in the tpv constructor?
            If so, then you can simply remove that call from constructor and call it outside:

            tpv *open = new tpv(this);
            connect(open,&prueba::statusconexion,this,&inicio::changeconexionstatus);
            open->check_connection();
            

            Great!!! I look stupid, this is the simple solution:-)

            Thank so much for your support @jsulm

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved