Results 1 to 5 of 5

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

  1. #1
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

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

    Hello!

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

    Here are the headers of my files:

    ControlLoop.h

    #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;


    ControlLoop .cpp

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

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


    And the StartGUI files:

    startgui.h

    #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:
    on_JobLineEdit_textChanged(QString)
    ....
    }


    StartGui.cpp

    #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:n_JobLineEdit_textChanged(QString)
    {
    ...
    }
    ...
    }

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

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

    oh wow, what are you doing here? Learn some c++ and what inheritance is for first, please.

    StartGui already IS a ControlLoop. Why are you using StartGui to make ANOTHER ControlLoop??

    Oh yeah, use code tags as well!!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

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

    I know! I'm a beginner, please excuse my lack of knowledge...
    I will keep reading about inheritance and so, but could you please tell me if it is even possible to access the widget from the StartGui?

    Without making another ControlLoop it would look like this:
    connect(ui->JobLineEdit, SIGNAL(textChanged(QString)),
    this, SLOT(on_JobLineEdit_textChanged(QString)));

    Is it even possible to achieve that, or is the whole idea just wrong?

    Thank you very much!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    Quote Originally Posted by saralicia View Post
    Without making another ControlLoop it would look like this:
    connect(ui->JobLineEdit, SIGNAL(textChanged(QString)),
    this, SLOT(on_JobLineEdit_textChanged(QString)));

    Is it even possible to achieve that, or is the whole idea just wrong?
    This should be OK, ui needs to be accessible to StartGui, so it needs to be protected (or public) in ControlLoop.

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

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

    should just get rid of startgui tbh.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 4
    Last Post: 25th October 2012, 18:29
  2. Access Object Created by javascript in qml
    By alizadeh91 in forum Qt Quick
    Replies: 6
    Last Post: 23rd February 2012, 15:06
  3. Replies: 0
    Last Post: 19th September 2011, 16:10
  4. How to access Widgets created in Tab View
    By kapoorsudhish in forum Newbie
    Replies: 5
    Last Post: 23rd October 2009, 13:12
  5. Replies: 3
    Last Post: 27th December 2008, 19:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.