Results 1 to 4 of 4

Thread: Access UI Components from different source files

  1. #1
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Access UI Components from different source files

    The Source File of my Application got really large. Thats why I wanted to split it into multiple files.
    I ran into the following problem:
    In class A I initialize the UI. But how can I check the state of components (i.e. checkstate of checkbox) from another source file?
    class A conntects PushButtons to functions in class B and class B needs to know the checkstates of some components.
    Obiously I can't include class A in class B and class B in class A becaue this would lead into a cycle and the program won't compile/start.

    I hope someone can help me to solve this Problem.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access UI Components from different source files

    well, u r gonna hv to set the 'ui' variable public.. then u can access its different components in different files

  3. #3
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Access UI Components from different source files

    My UI is defined like this

    mainwindow.h
    Qt Code:
    1. #include <QMainWindow>
    2. #include "ui_mainwindow.h"
    3. #include "main_print_functions.h"
    4. class MainWindow : public QMainWindow, public Ui::MainWindow {
    5. Q_OBJECT
    6.  
    7. public:
    8. MainWindow();
    9. .
    10. .
    11. .
    12. };
    To copy to clipboard, switch view to plain text mode 

    So how can I access the components in main_print_functions class?
    This doesn't work:
    Qt Code:
    1. MainWindow gui;
    2. gui.checkBox->isChecked()
    To copy to clipboard, switch view to plain text mode 

    Can you post a piece of code that shows me how to do this?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access UI Components from different source files

    Quote Originally Posted by cevou View Post
    This doesn't work:
    Qt Code:
    1. MainWindow gui;
    2. gui.checkBox->isChecked()
    To copy to clipboard, switch view to plain text mode 
    It should work. Are you sure that your check box is called "checkBox"?

    BTW, it's not a good practice to access GUI components directly from other classes. If you change something in your GUI, you will have to fix code in many places.

Similar Threads

  1. Access violation when reading big text files
    By robertson1 in forum General Programming
    Replies: 0
    Last Post: 18th September 2008, 06:59
  2. How to access files from specific folder using QContentSet
    By hrudhay in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 30th June 2008, 19:57
  3. Platform dependent source files: what is best?
    By ucomesdag in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2006, 18:52

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.