Results 1 to 7 of 7

Thread: Setting ui components from other file.

  1. #1
    Join Date
    Mar 2015
    Posts
    3

    Default Setting ui components from other file.

    Hi,
    Tryed to set ui from seperate file by :
    Qt Code:
    1. MainWin ee;
    2. ee.update_gui();
    To copy to clipboard, switch view to plain text mode 
    In ui-window cpp file it recives but no change to ui
    Qt Code:
    1. void MainWin::update_gui()
    2. {
    3. ui->label_4->setText("eeeeeeee");
    4. // ui->horizontalSlider->setValue(Lugemis_kaugus/LEVEL.size());
    5.  
    6. // ui->label_2->setNum(Lugemis_kaugus);
    7.  
    8. //double size = LEVEL.size();
    9.  
    10. // ui->label_3->setNum(size);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    Debug shows it executes but nothing changes on gui.
    How to solve this problem?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting ui components from other file.

    1. Show MainWin constructor body.
    2. What are You doing after update_gui() ? Show real code.

  3. #3
    Join Date
    Mar 2015
    Posts
    3

    Default Re: Setting ui components from other file.

    GUI.h file
    Qt Code:
    1. #ifndef MAINWIN_H
    2. #define MAINWIN_H
    3.  
    4. #include <QMainWindow>
    5.  
    6.  
    7. extern bool joonesta_kastid;
    8.  
    9.  
    10. extern double graph_red;
    11. extern double graph_green;
    12. extern double graph_blue;
    13.  
    14. namespace Ui {
    15. class MainWin;
    16. }
    17.  
    18. class MainWin : public QMainWindow
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. explicit MainWin(QWidget *parent = 0);
    24. ~MainWin();
    25.  
    26.  
    27. Ui::MainWin *ui;
    28.  
    29. private slots:
    30. void on_pushButton_clicked();
    31.  
    32.  
    33.  
    34.  
    35.  
    36.  
    37. void on_verticalSlider_valueChanged(int value);
    38.  
    39. void on_verticalSlider_2_valueChanged(int value);
    40.  
    41. void on_verticalSlider_3_valueChanged(int value);
    42.  
    43. void on_verticalSlider_4_valueChanged(int value);
    44.  
    45. void on_checkBox_2_toggled(bool checked);
    46.  
    47. void on_checkBox_toggled(bool checked);
    48.  
    49. void on_pushButton_2_clicked();
    50.  
    51. public slots:
    52.  
    53. void on_spinBox_valueChanged(int arg1);
    54.  
    55. void update_graph_colors();
    56.  
    57. void update_gui();
    58.  
    59. void uuenda_joonistus_seaded();
    60.  
    61. void on_horizontalSlider_valueChanged(int value);
    62.  
    63. };
    64.  
    65.  
    66. #endif // MAINWIN_H
    To copy to clipboard, switch view to plain text mode 

    GUI.cpp
    Qt Code:
    1. #include "mainwin.h"
    2. #include "ui_mainwin.h"
    3. #include <QThread>
    4. #include "openglwindow.h"
    5.  
    6. double graph_red;
    7. double graph_green;
    8. double graph_blue;
    9.  
    10. bool joonesta_kastid;
    11.  
    12. MainWin::MainWin(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWin)
    15. {
    16. ui->setupUi(this);
    17.  
    18. // ui->horizontalSlider->setDisabled(true);
    19.  
    20. }
    21.  
    22. MainWin::~MainWin()
    23. {
    24. delete ui;
    25. }
    26.  
    27. void MainWin::update_gui()
    28. {
    29.  
    30.  
    31. ui->label_4->setText("eeeeeeee"); <<------------------- it wont do anything visible on gui.
    32. // ui->horizontalSlider->setValue(Lugemis_kaugus/LEVEL.size());
    33.  
    34. // ui->label_2->setNum(Lugemis_kaugus);
    35.  
    36. //double size = LEVEL.size();
    37.  
    38. // ui->label_3->setNum(size);
    39.  
    40. }
    41. Removed some below
    To copy to clipboard, switch view to plain text mode 

    Try to execute:
    Qt Code:
    1. MainWin ee;
    2. ee.update_gui();
    To copy to clipboard, switch view to plain text mode 

    From main.cpp and it goes trough code lines in debug but labels string wont change.
    How to set ui components from seperate file?
    Last edited by anda_skoa; 23rd March 2015 at 10:08. Reason: changed [quote] to [code]

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting ui components from other file.

    Generally, objects on the screen are refreshed based on the event.

  5. #5
    Join Date
    Mar 2015
    Posts
    3

    Default Re: Setting ui components from other file.

    Can you please explain further or try sample on how to have gui set/update from other file?
    It appears not only updating gui wont work but also reading values from gui elements.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Setting ui components from other file.

    Please define what you mean by "won't work". How can reading a value "not work"? Do you get a crash or an invalid value? Also please provide a minimal compilable example reproducing the problem instead of dangling code snippets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Setting ui components from other file.

    Qt Code:
    1. MainWin ee;
    2. ee.update_gui();
    To copy to clipboard, switch view to plain text mode 

    And show us the complete method where you are doing this. If this code fragment is within a method exactly as you show it here, then what you are doing is this:

    1 - Creating a temporary MainWin on the stack: ( MainWin ee; )
    2 - Calling update_gui() on the temporary instance ( ee.update_gui(); )
    3 - Destroying that temporary instance as soon as the method exits.

    You aren't changing the actual MainWin instance that is part of your core GUI, you're changing a transient instance that never appears on screen (because this code never "shows" it).

    It appears not only updating gui wont work but also reading values from gui elements.
    And if you are trying to do that the same way you are trying to do this update, then there's your reason: you are trying to read the values from a temporary instance, not the instance that's showing in your GUI.

Similar Threads

  1. Replies: 0
    Last Post: 21st May 2011, 22:19
  2. about setting executable file icon
    By Raul in forum Qt Programming
    Replies: 5
    Last Post: 15th June 2010, 02:11
  3. Automatically setting up pro.user file parameters
    By purplecoast in forum Qt Tools
    Replies: 0
    Last Post: 23rd April 2010, 19:10
  4. Replies: 9
    Last Post: 9th April 2009, 06:49
  5. Setting OS Specified Icon on the File?
    By vishal.chauhan in forum Qt Programming
    Replies: 4
    Last Post: 31st May 2008, 12:37

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.