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. Trying to connect SecondWindow to MainWindow

Trying to connect SecondWindow to MainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 374 Views
  • 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.
  • E Offline
    E Offline
    Eshya
    wrote on last edited by
    #1

    hi, right now i am trying to connect secondwindow exec from mainwindow

    SecondWindow::SecondWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::SecondWindow)
    {
        ui->setupUi(this);
        MainWindow _main;
        connect(this,&SecondWindow::closeTimer,_main,&MainWindow::closeTimer);
    
    
    }
    

    what is the correct way to to this concept

    JonBJ 1 Reply Last reply
    0
    • E Eshya

      hi, right now i am trying to connect secondwindow exec from mainwindow

      SecondWindow::SecondWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::SecondWindow)
      {
          ui->setupUi(this);
          MainWindow _main;
          connect(this,&SecondWindow::closeTimer,_main,&MainWindow::closeTimer);
      
      
      }
      

      what is the correct way to to this concept

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Eshya said in Trying to connect SecondWindow to MainWindow:

      exec

      What does this mean? Are you by any chance thinking of QDialog::exec()??

      MainWindow _main;

      This cannot be right, it creates a brand new MainWindow. Not to mention that goes out of scope and gets destroyed at the closing }, so it won't be around for its slot to be called.

      If you have some two separate instances of some MainWindow and some SecondWindow, you can connect signals/slots across them once they have been created somewhere which knows about them, like:

      mainWindow = new MainWindow;
      secondWindow = new SecondWindow;
      connect(secondWindow, &SecondWindow::closeTimer, mainWindow, &MainWindow::closeTimer);
      

      or appropriate this if you call this somewhere within either MainWindow or SecondWindow classes. In the usual case SecondWindow should not know about MainWindow, so probably not inside SecondWindow class. And connect()s should not be done at the signalling side, only at the slot object side, or somewhere which can see both the signalling & slot objects.

      what is the correct way to to this concept

      Don't know till I understand what "concept" you are trying to implement.

      E 1 Reply Last reply
      1
      • JonBJ JonB

        @Eshya said in Trying to connect SecondWindow to MainWindow:

        exec

        What does this mean? Are you by any chance thinking of QDialog::exec()??

        MainWindow _main;

        This cannot be right, it creates a brand new MainWindow. Not to mention that goes out of scope and gets destroyed at the closing }, so it won't be around for its slot to be called.

        If you have some two separate instances of some MainWindow and some SecondWindow, you can connect signals/slots across them once they have been created somewhere which knows about them, like:

        mainWindow = new MainWindow;
        secondWindow = new SecondWindow;
        connect(secondWindow, &SecondWindow::closeTimer, mainWindow, &MainWindow::closeTimer);
        

        or appropriate this if you call this somewhere within either MainWindow or SecondWindow classes. In the usual case SecondWindow should not know about MainWindow, so probably not inside SecondWindow class. And connect()s should not be done at the signalling side, only at the slot object side, or somewhere which can see both the signalling & slot objects.

        what is the correct way to to this concept

        Don't know till I understand what "concept" you are trying to implement.

        E Offline
        E Offline
        Eshya
        wrote on last edited by
        #3

        @JonB no, i am doing this to call SecondWindow

        main.h

        SecondWindow *_secondwindow;
        

        main.cpp

        _secondwindow = new SecondWindow();
        _secondwindow->show()
        ```
        
        what I am trying to do is connect SecondWindow to emit function in MainWindow
        JonBJ jsulmJ 2 Replies Last reply
        0
        • E Eshya

          @JonB no, i am doing this to call SecondWindow

          main.h

          SecondWindow *_secondwindow;
          

          main.cpp

          _secondwindow = new SecondWindow();
          _secondwindow->show()
          ```
          
          what I am trying to do is connect SecondWindow to emit function in MainWindow
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Eshya
          So I gave you the code for exactly that in my answer.....

          1 Reply Last reply
          0
          • E Eshya

            @JonB no, i am doing this to call SecondWindow

            main.h

            SecondWindow *_secondwindow;
            

            main.cpp

            _secondwindow = new SecondWindow();
            _secondwindow->show()
            ```
            
            what I am trying to do is connect SecondWindow to emit function in MainWindow
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Eshya Isn't this same question as in https://forum.qt.io/topic/135973/how-to-connect-emitter-from-mainwindow-to-anotherwindow ?

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

            JonBJ 1 Reply Last reply
            2
            • jsulmJ jsulm

              @Eshya Isn't this same question as in https://forum.qt.io/topic/135973/how-to-connect-emitter-from-mainwindow-to-anotherwindow ?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @jsulm Very good observation...!

              1 Reply Last reply
              0

              • Login

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