call variable from other function
Hi.
Im declared one variable in ui.h:
Code:
class Ui_MainWindow
{
public:
..........
}
and I need call from function.cpp and this say on compile: "'label' undeclared"
Im include ui.h in function.cpp but is the same!
Any help?.
Thz
waly
Re: call variable from other function
It is really hard to say what your actual problem is with your limited example... but I would make sure that your "label" variable is scoped correctly when you are using it and that <QLabel> is included some how in your ui.h.
Re: call variable from other function
You need
in top of MainWindow.cpp
and
Code:
ui.label->setText("It's OK now!");
somewhere you need ))
Re: call variable from other function
Is by any chance that ui.h the result of uic?
Because you can't modify that directly. It will get overwritten every time you modify it in Designer.
Regards
Re: call variable from other function
Re: call variable from other function
it's code for example:
ui.h:
Code:
#ifndef UI_GUI_H
#define UI_GUI_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Ui_MainWindow
{
public:
{
.....
label = new QLabel(centralwidget
);
label
->setObjectName
(QString::fromUtf8("label"));
label
->setGeometry
(QRect(60,
100,
46,
14));
.......
retranslateUi(MainWindow);
//QObject::connect(pushButtonOpen, SIGNAL(clicked()), label, SLOT(clear()));
} // setupUi
{
........
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
#endif // UI_GUI_H
main.cpp:
Code:
#include <QtGui>
#include <QApplication>
#include "ventana.h"
int main(int argc, char *argv[])
{
intervalo = 0;
Ventana widget;
widget.show();
return app.exec();
}
ventana.h:
Code:
#include "ui.h"
class Ventana
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
Ventana();
public slots:
void Bopen();
void Bclose();
};
ventana.cpp:
Code:
#include <QtGui>
#include "ventana.h"
#include "function.h"
Ventana::Ventana()
{
setupUi(this);
connect(pushButtonOpen, SIGNAL(clicked()), this, SLOT(Bopen()));
connect(pushButtonClose, SIGNAL(clicked()), this, SLOT(Bclose()));
}
void Ventana::Bclose(){
label
->setText
(QString("CloseOk"));
functionDoSomething();
}
void Ventana::Bopen(){
}
From HERE im call label->setText();
But say is undeclared.
function.cpp:
Code:
#include <QtGui>
#include "function.h"
void functionDoSomething(){
//here call to Qlabel
label
->setText
(QString("HELLO WORLD"));
}
function.h:
Code:
void functionDoSomething();
Re: call variable from other function
you cannot add any members there.
Do it in designer, and uic will put them there.
Regards
Re: call variable from other function
Quote:
Originally Posted by
marcel
you cannot add any members there.
Do it in designer, and uic will put them there.
Regards
Im not understand!! :(
:confused: