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
Forum Updated to NodeBB v4.3 + New Features

Trying to connect SecondWindow to MainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 376 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 22 Apr 2022, 10:25 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

    J 1 Reply Last reply 22 Apr 2022, 10:35
    0
    • E Eshya
      22 Apr 2022, 10:25

      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

      J Offline
      J Offline
      JonB
      wrote on 22 Apr 2022, 10:35 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 22 Apr 2022, 10:42
      1
      • J JonB
        22 Apr 2022, 10:35

        @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 22 Apr 2022, 10:42 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
        J J 2 Replies Last reply 22 Apr 2022, 10:54
        0
        • E Eshya
          22 Apr 2022, 10:42

          @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
          J Offline
          J Offline
          JonB
          wrote on 22 Apr 2022, 10:54 last edited by
          #4

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

          1 Reply Last reply
          0
          • E Eshya
            22 Apr 2022, 10:42

            @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
            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 22 Apr 2022, 11:46 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

            J 1 Reply Last reply 22 Apr 2022, 11:49
            2
            • J jsulm
              22 Apr 2022, 11:46

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

              J Offline
              J Offline
              JonB
              wrote on 22 Apr 2022, 11:49 last edited by
              #6

              @jsulm Very good observation...!

              1 Reply Last reply
              0

              4/6

              22 Apr 2022, 10:54

              • Login

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