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. Connecting two windows
Qt 6.11 is out! See what's new in the release blog

Connecting two windows

Scheduled Pinned Locked Moved Solved General and Desktop
40 Posts 7 Posters 10.9k Views 4 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 russjohn834

    @JonB

    I tried this:

    connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);
    

    this throws a different error:

    stageone.cpp:11:5: error: no matching member function for call to 'connect'
    qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
    qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
    qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
    qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
    qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
    qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
    qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
    qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #6

    @russjohn834
    In answer to your new messages, when you wrote earlier

    &MainWindow::patientID is a signal which is emitted as

    emit patientID(selection[0].data().toString());

    this is not good enough for people to help you, I would suggest. We need to see the definition in the .cpp file and the declaration in the .h file....

    1 Reply Last reply
    1
    • R russjohn834

      @JonB

      I tried this:

      connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);
      

      this throws a different error:

      stageone.cpp:11:5: error: no matching member function for call to 'connect'
      qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
      qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
      qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
      qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
      qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
      qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
      qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
      qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @russjohn834 Please show the exact declaration of patientID...

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        russjohn834
        wrote on last edited by russjohn834
        #8

        @jsulm Hi,

        I declared patientID as:

        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
            StageTwoNew *stagetwonew;
            StageOne *stageone;
        
        signals:
        
            void patientID(QString);  ----------------> signal declaration
        
        
        public slots:
            void on_pushButton_New_clicked();
        
            void on_pushButton_Open_clicked();
        
            void parseDataEntry(const QString dataPath);
        
        private:
            Ui::MainWindow *ui;
        
        };
        #endif // MAINWINDOW_H
        
        jsulmJ 1 Reply Last reply
        0
        • R russjohn834

          @jsulm Hi,

          I declared patientID as:

          QT_BEGIN_NAMESPACE
          namespace Ui { class MainWindow; }
          QT_END_NAMESPACE
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              MainWindow(QWidget *parent = nullptr);
              ~MainWindow();
              StageTwoNew *stagetwonew;
              StageOne *stageone;
          
          signals:
          
              void patientID(QString);  ----------------> signal declaration
          
          
          public slots:
              void on_pushButton_New_clicked();
          
              void on_pushButton_Open_clicked();
          
              void parseDataEntry(const QString dataPath);
          
          private:
              Ui::MainWindow *ui;
          
          };
          #endif // MAINWINDOW_H
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #9

          @russjohn834 Looks good. Try a complete rebuild: delete build folder, run qmake and then build.

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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            russjohn834
            wrote on last edited by russjohn834
            #10

            @jsulm

            I'm getting still the same error:

            stageone.cpp:11:5: error: no matching member function for call to 'connect'
            qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
            qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
            qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
            qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
            qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
            qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
            qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
            qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
            

            This is how I call the connect:

            #include "stageone.h"
            #include "ui_stageone.h"
            #include "mainwindow.h"
            
            StageOne::StageOne(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::StageOne)
            {
                ui->setupUi(this);
            
                connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);  //
            
            }
            
            

            Any idea?

            J.HilkJ 1 Reply Last reply
            0
            • R russjohn834

              @jsulm

              I'm getting still the same error:

              stageone.cpp:11:5: error: no matching member function for call to 'connect'
              qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
              qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
              qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
              qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
              qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
              qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
              qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
              qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
              

              This is how I call the connect:

              #include "stageone.h"
              #include "ui_stageone.h"
              #include "mainwindow.h"
              
              StageOne::StageOne(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::StageOne)
              {
                  ui->setupUi(this);
              
                  connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);  //
              
              }
              
              

              Any idea?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #11

              @russjohn834

              do you happen to have a function body inside mainwindow.cpp ?

              somethinglike:
              void MainWindow::patientID(QString string)

              That's not allowed for signals


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #12

                @russjohn834 said in Connecting two windows:

                connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);

                Oh its much simpler

                You class is not called MainWindow, but StageOne

                connect(this, &StageOne::patientID, ui->label, &QLabel::setText); 
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                jsulmJ 1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @russjohn834 said in Connecting two windows:

                  connect(this, &MainWindow::patientID, ui->label, &QLabel::setText);

                  Oh its much simpler

                  You class is not called MainWindow, but StageOne

                  connect(this, &StageOne::patientID, ui->label, &QLabel::setText); 
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  @J-Hilk @russjohn834 I'm lost. The signal is declared in MainWindow, but connect is in StageOne.
                  @russjohn834 What is it now?!

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

                  1 Reply Last reply
                  3
                  • R Offline
                    R Offline
                    russjohn834
                    wrote on last edited by
                    #14

                    @jsulm @J-Hilk ,

                    Still the same issue.

                    I changed the name of signal from patientID to patientIdChanged.

                    signal is Declared and emitted in MainWindow. Connection is in StageOne (with a QLabel).

                    StageOne::StageOne(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::StageOne)
                    {
                        ui->setupUi(this);
                    
                        connect(this, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  //
                    }
                    

                    the error says:

                    stageone.cpp:11:5: error: no matching member function for call to 'connect'
                    qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
                    qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
                    qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
                    qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
                    qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
                    qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
                    qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                    qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                    
                    jsulmJ 1 Reply Last reply
                    0
                    • R russjohn834

                      @jsulm @J-Hilk ,

                      Still the same issue.

                      I changed the name of signal from patientID to patientIdChanged.

                      signal is Declared and emitted in MainWindow. Connection is in StageOne (with a QLabel).

                      StageOne::StageOne(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::StageOne)
                      {
                          ui->setupUi(this);
                      
                          connect(this, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  //
                      }
                      

                      the error says:

                      stageone.cpp:11:5: error: no matching member function for call to 'connect'
                      qobject.h:228:43: note: candidate function [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)] not viable: no known conversion from 'StageOne *' to 'const typename QtPrivate::FunctionPointer<void (MainWindow::*)(QString)>::Object *' (aka 'const MainWindow *') for 1st argument
                      qobject.h:208:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
                      qobject.h:211:36: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const QMetaMethod' for 2nd argument
                      qobject.h:463:41: note: candidate function not viable: no known conversion from 'void (MainWindow::*)(QString)' to 'const char *' for 2nd argument
                      qobject.h:269:13: note: candidate template ignored: requirement '!QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::IsPointerToMemberFunction' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
                      qobject.h:308:13: note: candidate template ignored: requirement 'QtPrivate::FunctionPointer<void (QLabel::*)(const QString &)>::ArgumentCount == -1' was not satisfied [with Func1 = void (MainWindow::*)(QString), Func2 = void (QLabel::*)(const QString &)]
                      qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                      qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided
                      
                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #15

                      @russjohn834 Come on it is not about patientID!
                      In the connect bellow this is NOT MainWindow, but StageOne!
                      It simply can't work this way!

                      StageOne::StageOne(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::StageOne)
                      {
                          ui->setupUi(this);
                      
                          connect(this, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  // this != MaiNWindow*!
                      }
                      

                      If you want to connect in StageOne then you need an instance of MainWindow:

                      StageOne::StageOne(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::StageOne)
                      {
                          ui->setupUi(this);
                          MainWindow *mainWindow = new MainWindow(...);
                          connect(mainWindow, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  // this != MaiNWindow*!
                      }
                      

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

                      JonBJ 1 Reply Last reply
                      5
                      • jsulmJ jsulm

                        @russjohn834 Come on it is not about patientID!
                        In the connect bellow this is NOT MainWindow, but StageOne!
                        It simply can't work this way!

                        StageOne::StageOne(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::StageOne)
                        {
                            ui->setupUi(this);
                        
                            connect(this, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  // this != MaiNWindow*!
                        }
                        

                        If you want to connect in StageOne then you need an instance of MainWindow:

                        StageOne::StageOne(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::StageOne)
                        {
                            ui->setupUi(this);
                            MainWindow *mainWindow = new MainWindow(...);
                            connect(mainWindow, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);  // this != MaiNWindow*!
                        }
                        
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #16

                        @jsulm
                        This is partly due to my bad... :(

                        No declaration of StageOne was shown. I quickly read:

                        StageOne::StageOne(QWidget *parent) :
                            QMainWindow(parent)
                        

                        I read it too quickly, and thought StageOne was derived from QMainWindow. Comes from doing Python all the time instead of C++. So I misled OP by saying put in this where he should have mainWindow, my fault not his!

                        jsulmJ 1 Reply Last reply
                        2
                        • R Offline
                          R Offline
                          russjohn834
                          wrote on last edited by
                          #17

                          I'm a bit lost!

                          I now get a different error

                          mainwindow.h:25: error: C2143: syntax error: missing ';' before '*'
                          mainwindow.h:25: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                          mainwindow.h:25: error: C2238: unexpected token(s) preceding ';'
                          

                          this is my mainwindow.h

                          #ifndef MAINWINDOW_H
                          #define MAINWINDOW_H
                          
                          #include <QMainWindow>
                          #include <QDebug>
                          #include <QFile>
                          #include <QDirIterator>
                          #include <QXmlStreamReader>
                          #include <QMessageBox>
                          #include "stagetwonew.h"
                          #include "stageone.h"
                          
                          QT_BEGIN_NAMESPACE
                          namespace Ui { class MainWindow; }
                          QT_END_NAMESPACE
                          
                          class MainWindow : public QMainWindow
                          {
                              Q_OBJECT
                          
                          public:
                              MainWindow(QWidget *parent = nullptr);
                              ~MainWindow();
                              StageTwoNew *stagetwonew;
                              StageOne *stageone;  ------------------>error points here
                          
                          signals:
                          
                              void patientIdChanged(QString);
                          
                          
                          private slots:
                          
                              void on_pushButton_New_clicked();
                          
                              void on_pushButton_Open_clicked();
                          
                              void parseDataEntry(const QString dataPath);
                          
                          private:
                              Ui::MainWindow *ui;
                          
                          };
                          #endif // MAINWINDOW_H
                          

                          I tried complete rebuild, no luck

                          Any ideas where I'm wrong?

                          JonBJ 1 Reply Last reply
                          0
                          • R russjohn834

                            I'm a bit lost!

                            I now get a different error

                            mainwindow.h:25: error: C2143: syntax error: missing ';' before '*'
                            mainwindow.h:25: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                            mainwindow.h:25: error: C2238: unexpected token(s) preceding ';'
                            

                            this is my mainwindow.h

                            #ifndef MAINWINDOW_H
                            #define MAINWINDOW_H
                            
                            #include <QMainWindow>
                            #include <QDebug>
                            #include <QFile>
                            #include <QDirIterator>
                            #include <QXmlStreamReader>
                            #include <QMessageBox>
                            #include "stagetwonew.h"
                            #include "stageone.h"
                            
                            QT_BEGIN_NAMESPACE
                            namespace Ui { class MainWindow; }
                            QT_END_NAMESPACE
                            
                            class MainWindow : public QMainWindow
                            {
                                Q_OBJECT
                            
                            public:
                                MainWindow(QWidget *parent = nullptr);
                                ~MainWindow();
                                StageTwoNew *stagetwonew;
                                StageOne *stageone;  ------------------>error points here
                            
                            signals:
                            
                                void patientIdChanged(QString);
                            
                            
                            private slots:
                            
                                void on_pushButton_New_clicked();
                            
                                void on_pushButton_Open_clicked();
                            
                                void parseDataEntry(const QString dataPath);
                            
                            private:
                                Ui::MainWindow *ui;
                            
                            };
                            #endif // MAINWINDOW_H
                            

                            I tried complete rebuild, no luck

                            Any ideas where I'm wrong?

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

                            @russjohn834

                            #include "stagetwonew.h"
                            #include "stageone.h"
                            ...
                                StageTwoNew *stagetwonew;
                                StageOne *stageone;  ------------------>error points here
                            

                            Prove to us/yourself that those two header files declare StageTwoNew & StageOne as classes? (Having said that, I'd more have expected "undeclared", but at least check what I've said, even if I did mis-lead you earlier :) )

                            1 Reply Last reply
                            2
                            • JonBJ JonB

                              @jsulm
                              This is partly due to my bad... :(

                              No declaration of StageOne was shown. I quickly read:

                              StageOne::StageOne(QWidget *parent) :
                                  QMainWindow(parent)
                              

                              I read it too quickly, and thought StageOne was derived from QMainWindow. Comes from doing Python all the time instead of C++. So I misled OP by saying put in this where he should have mainWindow, my fault not his!

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

                              @JonB said in Connecting two windows:

                              I read it too quickly, and thought StageOne was derived from QMainWindow

                              It apparently is derived from QMainWindow, but this does not have anything to do with your MainWindow.
                              Does StageOne include mainwindow.h? If so you have circular dependency.

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

                              1 Reply Last reply
                              3
                              • R Offline
                                R Offline
                                russjohn834
                                wrote on last edited by
                                #20

                                @jsulm , @JonB

                                @jsulm said in Connecting two windows:

                                Does StageOne include mainwindow.h? If so you have circular dependency.

                                Yes. StageOne inlcude mainwindow.h. Any suggestion, How do I go about with circular dependency in this scenario?

                                Or is there a better way to do this (connect between two forms (QMainWindow))?

                                Pablo J. RoginaP 1 Reply Last reply
                                0
                                • R russjohn834

                                  @jsulm , @JonB

                                  @jsulm said in Connecting two windows:

                                  Does StageOne include mainwindow.h? If so you have circular dependency.

                                  Yes. StageOne inlcude mainwindow.h. Any suggestion, How do I go about with circular dependency in this scenario?

                                  Or is there a better way to do this (connect between two forms (QMainWindow))?

                                  Pablo J. RoginaP Offline
                                  Pablo J. RoginaP Offline
                                  Pablo J. Rogina
                                  wrote on last edited by
                                  #21

                                  @russjohn834 could you please state your requirement again?
                                  How are the window(s) suppose to work together?
                                  What data you want from what window updating what widget in what other window?

                                  Upvote the answer(s) that helped you solve the issue
                                  Use "Topic Tools" button to mark your post as Solved
                                  Add screenshots via postimage.org
                                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                  1 Reply Last reply
                                  2
                                  • R Offline
                                    R Offline
                                    russjohn834
                                    wrote on last edited by
                                    #22

                                    @Pablo-J-Rogina Hi,

                                    There are two forms.
                                    MainWindow and StageOne (Both inherits QMainWindow).

                                    MainWindow has a signal patientIdChanged(QString), which is emitted upon clicking a button, I did this:

                                    void MainWindow::on_pushButton_Open_clicked()
                                    {
                                    
                                        QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                                    
                                        this->hide();
                                        stageone = new StageOne(this);
                                        stageone->show();
                                        
                                      emit patientIdChanged(selection[0].data().toString());
                                        
                                        
                                    }
                                    

                                    And in StageOne I have a QLabel, its setText should get signal (Qstring) value from MainwWndow and show. That's the requirement.

                                    I tried to do this in StageOne:

                                     MainWindow *mainWindow= new MainWindow(this);
                                    connect(mainWindow, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);
                                    
                                    

                                    But this is not working

                                    Pablo J. RoginaP 1 Reply Last reply
                                    0
                                    • R russjohn834

                                      @Pablo-J-Rogina Hi,

                                      There are two forms.
                                      MainWindow and StageOne (Both inherits QMainWindow).

                                      MainWindow has a signal patientIdChanged(QString), which is emitted upon clicking a button, I did this:

                                      void MainWindow::on_pushButton_Open_clicked()
                                      {
                                      
                                          QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                                      
                                          this->hide();
                                          stageone = new StageOne(this);
                                          stageone->show();
                                          
                                        emit patientIdChanged(selection[0].data().toString());
                                          
                                          
                                      }
                                      

                                      And in StageOne I have a QLabel, its setText should get signal (Qstring) value from MainwWndow and show. That's the requirement.

                                      I tried to do this in StageOne:

                                       MainWindow *mainWindow= new MainWindow(this);
                                      connect(mainWindow, &MainWindow::patientIdChanged, ui->label, &QLabel::setText);
                                      
                                      

                                      But this is not working

                                      Pablo J. RoginaP Offline
                                      Pablo J. RoginaP Offline
                                      Pablo J. Rogina
                                      wrote on last edited by Pablo J. Rogina
                                      #23

                                      @russjohn834 said in Connecting two windows:

                                      Ok, it looks like you're overcomplicating things here.

                                      So you want a string (some selection in MainWindow widget) passed to StageOne window, right?
                                      What about having the StageOne constructor receiving such string? Pseudo-code:

                                      void MainWindow::on_pushButton_Open_clicked()
                                      {
                                           QModelIndexList selection=ui->tableWidget->selectionModel()->selectedRows(0);
                                       
                                           this->hide();
                                           stageone = new StageOne(selection[0].data().toString(), this);
                                           stageone->show();
                                      ...
                                      

                                      and obviusly StageOne class need a change in constructor:

                                      StageOne::StageOne(Qstring someString, QWidget *parent) :
                                          QMainWindow(parent),
                                          ui(new Ui::StageOne)
                                      {
                                      ...
                                      

                                      I don't see the need to deal with signals here

                                      Upvote the answer(s) that helped you solve the issue
                                      Use "Topic Tools" button to mark your post as Solved
                                      Add screenshots via postimage.org
                                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                      1 Reply Last reply
                                      3
                                      • R Offline
                                        R Offline
                                        russjohn834
                                        wrote on last edited by
                                        #24

                                        @Pablo-J-Rogina Thanks a lot that's exactly I was trying for.

                                        1 Reply Last reply
                                        0
                                        • R Offline
                                          R Offline
                                          russjohn834
                                          wrote on last edited by
                                          #25

                                          Thank you @JonB, @jsulm , @J-Hilk and @Pablo-J-Rogina for your feedback

                                          jsulmJ 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