PDA

View Full Version : Problem with QLineEdit and setText



Elmo23x
11th April 2007, 16:26
I have a pice of code that looks like this...


...
QLineEdit *t1;
QString str;

t1 = new QLineEdit();
str = "hi to everybody";

t1->setText(str);
...

After the execution of "t1->setText(str);" the program breaks with a segmentation fault error.

Probably I am doing something very badly.

Thank you for your help

BTW: the code compiles without any error :)

high_flyer
11th April 2007, 16:38
The code you posted should work ok.
Are you sure it crashes on t1->setText(str) and not later?
Could you show a bit more of the code before and after the lines you posted?

Elmo23x
11th April 2007, 16:53
The exact code is this (sorry, names are in spanish):


void WInfo::cargar_info_personal()
{
int sexo, pais;
int dia, mes, ano;
QString nick;
QString nombre;
QString apellido;
QString ciudad;

//Get the information
datos_leer_info_personal(estDatos, &nick, &nombre, &apellido, &ciudad,
&sexo, &pais, &dia, &mes, &ano);

QDate fecha(ano, mes, dia);

t1->setText(nick);
t2->setText(nombre);
t3->setText(apellido);
c4->setCurrentIndex(sexo);
c5->setCurrentIndex(0);
t6->setText(ciudad);
f7->setDate(fecha);
}

I have been debugging it with gdb, and it breaks in "t1->setText(nick);" if I comment it it breaks in "t2->setText(nombre);", byt if I write "t1->setText("string");" it works without problems.

t* are declared in the header of the class and initilialized when the class is created.

J-jayz-Z
11th April 2007, 17:07
I think you have to take a look at "datos_leer_info_personal".
Test the values of "nick" etc. ...

Elmo23x
11th April 2007, 20:49
I checked it already, I tried to give values to the QStrings after calling datos_leer_info_personal();

and all is the same... :(

jacek
11th April 2007, 20:51
Are you sure that t1, t2 and t3 are initialized before cargar_info_personal() is invoked?

high_flyer
11th April 2007, 21:42
Try cleaning the project an rebuild.
See if it still crashes.
If it does:
comment out datos_leer_info_personal() and try.
Then please post the code inside datos_leer_info_personal().

giverson
11th April 2007, 23:01
I would try any other function that requires a QString as input and see if it breaks the same way. My guess is it has something to do with how your QString is initialized.

Elmo23x
12th April 2007, 12:35
Thanks to everybody. I just reinstaled QT 4 libraries and it works now. This magic of computers :(