PDA

View Full Version : Problem accesing widgets



Greender
5th February 2009, 21:33
Hi, I'm really new to QT and c++ and was doing something with QTcreator I designed a ui, and I tried to put some functionality in it by modifiyng the cpp from the ui.


#include "cliente.h"
#include "ui_cliente.h"
#include "QDialogButtonBox"


Cliente::Cliente(QWidget *parent)
: QMainWindow(parent), ui(new Ui::ClienteClass)
{


ui->setupUi(this);

QString text = ui->direccionLE->text();

connect(ui->conectarB, SIGNAL(clicked()),this, SLOT(accion()));

}

void accion(){
//
QString text = ui->direccionLE->text();



}

Cliente::~Cliente()
{
delete ui;

}

The problem is that I can't acces say (QString text = ui->direccionLE->text();) in the function accion because ui is not declared in that scope, I know this might be a really stupid question, bur how do I acces widgets from the ui in a function (lineedits, comboboxes, ...)

Thanks for your patience

faldzip
5th February 2009, 23:26
void accion() {
QString text = ui->direccionLE->text();

}

You are defining here a global finction wich has nothing to do with your class Cliente.

You should do it like this:


void Cliente::accion() {
QString text = ui->direccionLE->text();
}

Notice that "Cliente::" before "accion()", in simple way - it's necessary to tell that your accion() is from Cliente class (I hope you declared it in class declaration...)

Anyway, these are basics of C++ language so get some C++ book/tutorial.

Greender
6th February 2009, 00:30
Thank you very much.

now everything builds and compiles fine but...


void Cliente::accion(){
ui->direccionLE->setText("Some Text");
ui->consulta1L->setText("text");
ui->consulta1LE->setText("prueba");
}

when I try my code it does't seem to change the values in the ui, why's that?

aamer4yu
6th February 2009, 07:02
what do u mean by "try my code" ?

You have connected accion with ui->conectarB. Are you pressing the button ?

Greender
6th February 2009, 13:14
Ok, by try I mean, when I execute the code and press the button connected to the function nothing changes in the QlineEdits and labesl that are supposed to change.