PDA

View Full Version : Setting ui components from other file.



QQQ
22nd March 2015, 18:19
Hi,
Tryed to set ui from seperate file by :


MainWin ee;
ee.update_gui();
In ui-window cpp file it recives but no change to ui



void MainWin::update_gui()
{
ui->label_4->setText("eeeeeeee");
// ui->horizontalSlider->setValue(Lugemis_kaugus/LEVEL.size());

// ui->label_2->setNum(Lugemis_kaugus);

//double size = LEVEL.size();

// ui->label_3->setNum(size);

}

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

Lesiok
22nd March 2015, 19:31
1. Show MainWin constructor body.
2. What are You doing after update_gui() ? Show real code.

QQQ
23rd March 2015, 08:59
GUI.h file

#ifndef MAINWIN_H
#define MAINWIN_H

#include <QMainWindow>


extern bool joonesta_kastid;


extern double graph_red;
extern double graph_green;
extern double graph_blue;

namespace Ui {
class MainWin;
}

class MainWin : public QMainWindow
{
Q_OBJECT

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


Ui::MainWin *ui;

private slots:
void on_pushButton_clicked();






void on_verticalSlider_valueChanged(int value);

void on_verticalSlider_2_valueChanged(int value);

void on_verticalSlider_3_valueChanged(int value);

void on_verticalSlider_4_valueChanged(int value);

void on_checkBox_2_toggled(bool checked);

void on_checkBox_toggled(bool checked);

void on_pushButton_2_clicked();

public slots:

void on_spinBox_valueChanged(int arg1);

void update_graph_colors();

void update_gui();

void uuenda_joonistus_seaded();

void on_horizontalSlider_valueChanged(int value);

};


#endif // MAINWIN_H


GUI.cpp

#include "mainwin.h"
#include "ui_mainwin.h"
#include <QThread>
#include "openglwindow.h"

double graph_red;
double graph_green;
double graph_blue;

bool joonesta_kastid;

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

// ui->horizontalSlider->setDisabled(true);

}

MainWin::~MainWin()
{
delete ui;
}

void MainWin::update_gui()
{


ui->label_4->setText("eeeeeeee"); <<------------------- it wont do anything visible on gui.
// ui->horizontalSlider->setValue(Lugemis_kaugus/LEVEL.size());

// ui->label_2->setNum(Lugemis_kaugus);

//double size = LEVEL.size();

// ui->label_3->setNum(size);

}
Removed some below


Try to execute:

MainWin ee;
ee.update_gui();

From main.cpp and it goes trough code lines in debug but labels string wont change.
How to set ui components from seperate file?

Lesiok
23rd March 2015, 10:38
Generally, objects on the screen are refreshed based on the event.

QQQ
23rd March 2015, 13:59
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.

wysota
23rd March 2015, 14:10
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.

d_stranz
23rd March 2015, 16:51
MainWin ee;
ee.update_gui();


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.