PDA

View Full Version : Simple error :P



Lebowski
7th June 2006, 11:03
I've created a form named startno. Inside I have a QLineEdit object named line. I would like to change text in this field by writing code into startno.ui.h.

If I use it inside a function (like after button click) it works ok. Working example:

void startno::changeso_clicked()
{
line->setText("test1");
}

If I try to write text to that field outside of any function I get an error. Non-working example:

line->setText("test1");


I know I can set this text in property editor. But I would like to find a solution for this for future :)

wysota
7th June 2006, 12:12
This is really a C++ issue. You have to follow C++ rules for accessing objects. If "line" is a member of class "startno" you have to access it using an object of class "startno" and not as a "hanging in void" object "line".

BrainB0ne
8th June 2006, 15:31
maybe it will help you if you set the text in the constructor of the form (at the ui.h file it is the init() function), simply create it :)



void startno::init()
{
line->setText("test1");
}


then your text will be set upon creation of the form.

sunil.thaha
9th June 2006, 05:31
Or . U could use the designer to set the text initially.

Generally It's good not to use the ui.h approach, rather use the subclassing one.

U will find help on this approach in the designers man pages.

under the section Subclassing and Dynamic Dialogs