December 30, 2012

saralicia saralicia
Lab Rat
1 posts

How to access widgets created with the UI Designer from another (a sub) class.

 

Hello!

I’m a begginer, started this month programming with QT. So long I’ve been able to create a GUI (ControlLoop) with the QT Designer and access its widgets with signals and slots declared in the Sourcefile. Now I have a new class (StartGui) which inherits from ControlLoop. In StartGui I’m trying to catch the signals from the ControlLoop’s widgets at runtime, I have tried almost everything I’ve read. I connect the signals and slots in der StartGui class and get no error messages. But whenever the program is running and I change the Text in e.g. a QLineEdit, nothing happens. Could you please help me? I’ve been stuck at this point for days.

I don’t know what I’m doing wrong whenever I connect the Widgets, the nothing happens when the programm is running and I do any of the signals.

Is it even possible to acces those widgets from the subclass or is the whole idea just wrong=

Thank you very much!

  1. #ifndef CONTROLLOOP_H
  2. #define CONTROLLOOP_H
  3.  
  4. #include <QObject>
  5. #include <QMainWindow>
  6.  
  7. namespace Ui {
  8. class ControlLoop;
  9. }
  10.  
  11. class ControlLoop : public QMainWindow
  12. {
  13.     Q_OBJECT
  14.    
  15. public:
  16.     explicit ControlLoop(QWidget *parent = 0);
  17.     ~GUIRegelKreis();
  18.    
  19.     Ui::ControlLoop *ui;
  20. ...
  21. }

  1. #include "controloop.h"
  2. #include "ui_controloop.h"
  3.  
  4. ControLoop::ControLoop(QWidget *parent) :
  5.     QMainWindow(parent),
  6.     ui(new Ui::ControLoop)
  7. {
  8.     ui->setupUi(this);
  9. }

  1. #ifndef STARTGUI_H
  2. #define STARTGUI_H
  3.  
  4. #include "controlloop.h"
  5. #include "ui_guiregelkreis.h"
  6.  
  7. class StartGui : public ControlLoop
  8. {
  9.  
  10.     Q_OBJECT
  11.  
  12. public:
  13.     StartGui();
  14.     ControlLoop *GUI;
  15.  
  16. public slots:
  17.     void on_JobLineEdit_textChanged(QString)
  18. ....
  19. }

  1. #include "startgui.h"
  2. #include "ui_controlloop.h"
  3.  
  4.  
  5. StartGui::StartGui()
  6. {
  7.  
  8.    GUI = new ControlLoop();
  9.  
  10.     connect(GUI->ui->JobLineEdit, SIGNAL(textChanged(QString)),
  11.             this, SLOT(on_JobLineEdit_textChanged(QString)));
  12.     connect(GUI->ui->MaschineLineEdit, SIGNAL(textChanged(QString)),
  13.             this, SLOT(on_MaschineLineEdit_textChanged(QString)));
  14.  
  15. ....
  16.  
  17. void StartGui::on_JobLineEdit_textChanged(QString)
  18. {
  19. ...
  20. }
  21. ...
  22. }

2 replies

December 30, 2012

bkerdev bkerdev
Lab Rat
49 posts

did you declare on_MaschineLineEdit_textChanged(QString)

 Signature 

Boris Bker

December 30, 2012

Wilk Wilk
Lab Rat
119 posts

Hello.
I’m sorry, but it’s not QT, it’s Qt.
Also, why do you need this inheritence? Just make your class for main window, draw interface for it and then right-click on desired element and choose “Go to slot”.

 
  ‹‹ Qt5 QWidget project dependencies? OpenGL? Direct3D? WTH?      Understanding GPL and LGPL ››

You must log in to post a reply. Not a member yet? Register here!