Results 1 to 9 of 9

Thread: Problem with QLineEdit and setText

  1. #1
    Join Date
    Jan 2007
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with QLineEdit and setText

    I have a pice of code that looks like this...

    Qt Code:
    1. ...
    2. QString str;
    3.  
    4. t1 = new QLineEdit();
    5. str = "hi to everybody";
    6.  
    7. t1->setText(str);
    8. ...
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLineEdit and setText

    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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2007
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QLineEdit and setText

    The exact code is this (sorry, names are in spanish):

    Qt Code:
    1. void WInfo::cargar_info_personal()
    2. {
    3. int sexo, pais;
    4. int dia, mes, ano;
    5. QString nick;
    6. QString nombre;
    7. QString apellido;
    8. QString ciudad;
    9.  
    10. //Get the information
    11. datos_leer_info_personal(estDatos, &nick, &nombre, &apellido, &ciudad,
    12. &sexo, &pais, &dia, &mes, &ano);
    13.  
    14. QDate fecha(ano, mes, dia);
    15.  
    16. t1->setText(nick);
    17. t2->setText(nombre);
    18. t3->setText(apellido);
    19. c4->setCurrentIndex(sexo);
    20. c5->setCurrentIndex(0);
    21. t6->setText(ciudad);
    22. f7->setDate(fecha);
    23. }
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4

    Default Re: Problem with QLineEdit and setText

    I think you have to take a look at "datos_leer_info_personal".
    Test the values of "nick" etc. ...

  5. #5
    Join Date
    Jan 2007
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QLineEdit and setText

    I checked it already, I tried to give values to the QStrings after calling datos_leer_info_personal();

    and all is the same...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLineEdit and setText

    Are you sure that t1, t2 and t3 are initialized before cargar_info_personal() is invoked?

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QLineEdit and setText

    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().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: Problem with QLineEdit and setText

    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.

  9. #9
    Join Date
    Jan 2007
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QLineEdit and setText

    Thanks to everybody. I just reinstaled QT 4 libraries and it works now. This magic of computers

Similar Threads

  1. Replies: 1
    Last Post: 26th November 2006, 09:32
  2. QLineEdit - Float number not displayed correct
    By morty in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2006, 00:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.