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. How to access widgets created with the UI Designer from another (a sub) class.

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.4k 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.
  • S Offline
    S Offline
    saralicia
    wrote on last edited by
    #1

    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!

    @
    #ifndef CONTROLLOOP_H
    #define CONTROLLOOP_H

    #include <QObject>
    #include <QMainWindow>

    namespace Ui {
    class ControlLoop;
    }

    class ControlLoop : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit ControlLoop(QWidget *parent = 0);
    ~GUIRegelKreis();

    Ui::ControlLoop *ui;
    

    ...
    }
    @

    @
    #include "controloop.h"
    #include "ui_controloop.h"

    ControLoop::ControLoop(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ControLoop)
    {
    ui->setupUi(this);
    }
    @

    @
    #ifndef STARTGUI_H
    #define STARTGUI_H

    #include "controlloop.h"
    #include "ui_guiregelkreis.h"

    class StartGui : public ControlLoop
    {

    Q_OBJECT
    

    public:
    StartGui();
    ControlLoop *GUI;

    public slots:
    void on_JobLineEdit_textChanged(QString)
    ....
    }
    @

    @
    #include "startgui.h"
    #include "ui_controlloop.h"

    StartGui::StartGui()
    {

    GUI = new ControlLoop();

    connect(GUI->ui->JobLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(on_JobLineEdit_textChanged(QString)));
    connect(GUI->ui->MaschineLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(on_MaschineLineEdit_textChanged(QString)));
    

    ....

    void StartGui::on_JobLineEdit_textChanged(QString)
    {
    ...
    }
    ...
    }
    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bkerdev
      wrote on last edited by
      #2

      did you declare on_MaschineLineEdit_textChanged(QString)

      Boris Bker

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wilk
        wrote on last edited by
        #3

        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".

        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