Results 1 to 20 of 23

Thread: How to access the UI from another class ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: How to access the UI from another class ?

    d_stranz

    I really appreciated your explanations in this thread but have few questions related:

    How could you use a Class (Myclass) to initiate the signal as follows?

    connect( myClass, SIGNAL( sendText( const QString & ) ), myUIClass, SLOT( updateText( const QString & ) ) );

    In which QT program did you insert this Qt code (connect)?

    Thks in advance,

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,332
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    317
    Thanked 871 Times in 858 Posts

    Default Re: How to access the UI from another class ?

    If you don't understand something as basic to Qt as how to implement signals and slots, then you should spend some time studying the Qt documentation on them, and look at some of the QWidget examples, like the Calculator example.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: How to access the UI from another class ?

    I do not have problem with signals and slots which I used quite often in the Mainwindow in my apps.
    My concern is how to generate signals and slots between different classes.

    I figured out that 'myClass' in your connect example is actually an object but can't find what 'myUIClass' refers to in your example, I tried MainWindow but did not work.

    I wrote the connect function in the secondary class as follows:

    QObject::connect(objetA, SIGNAL(SendPlot()),MainWindow, SLOT(addPlot()) );

    but MainWindow is not recognized despite the following includes:

    #include "ui_mainwindow.h"
    #include "mainwindow.h"

    Your help appreciated !

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

    Default Re: How to access the UI from another class ?

    Quote Originally Posted by jps3001 View Post
    In which QT program did you insert this Qt code (connect)?
    The connect() call can be in any code where you have access to both the sender and the receiver object.
    The other two arguments are basically just strings.

    Quote Originally Posted by jps3001 View Post
    My concern is how to generate signals and slots between different classes.
    No difference, really.

    Quote Originally Posted by jps3001 View Post
    I figured out that 'myClass' in your connect example is actually an object but can't find what 'myUIClass' refers to in your example, I tried MainWindow but did not work.
    It refers to a different object than the one "myClass" refers to.
    Both these arguments are just pointers to QObject.

    Quote Originally Posted by jps3001 View Post
    I wrote the connect function in the secondary class as follows:

    QObject::connect(objetA, SIGNAL(SendPlot()),MainWindow, SLOT(addPlot()) );

    but MainWindow is not recognized despite the following includes:
    Do you have a QObject pointer variable named MainWindow?
    Given its capitalization it looks awefully like the name of a class.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: How to access the UI from another class ?

    You are right, Mainwindow is a Class and not an Object

    However I can't figure out how to implement the following:

    I need to add a Widget to ui->verticalLayout->addWidget(plot0)

    as you know ui is private, I intend to use connect to access a SLOT which will add this Widget(plot0)

    but I do not have an Object available in ui.

    Should I have to create a dummy object just for this ?

    I'm really puzzled !

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

    Default Re: How to access the UI from another class ?

    Aside from the fact that it is not very customary to send a QWidget pointer via a signal, the standard rules for signal/slot connects apply:

    You need to have access to both the sender and the receiver pointer at the place where you put the connect.

    So what good would a "dummy object" do?

    Forget about Qt or signal/slots until you have a place where you have access to both pointers.
    Basic C++.

    Cheers,
    _

  7. #7
    Join Date
    Jul 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: How to access the UI from another class ?

    No help available ??

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

    Default Re: How to access the UI from another class ?

    There are plenty of C++ tutorials online, some of them should cover object creation, passing data through methods, storing data in variable and members.

    Cheers,
    _

Similar Threads

  1. cannot access QLineEdit text in other methods of the class...
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 29th September 2009, 12:07
  2. Problem with QDialog class
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 09:03
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. Replies: 4
    Last Post: 26th June 2007, 19:19
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

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
  •  
Qt is a trademark of The Qt Company.