Results 1 to 14 of 14

Thread: weird QLineEdit bug that won't show its text...

  1. #1
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    Hi,

    I'm having a similar problem over a week... I tried everything... Created an Ui Form, created that form on code and both ways I can't get the QLineEdit to show it's text() value.

    Everything compiles fine and when running a function within the same class a the Widget was created, I keep getting an empty string when something is written on the lineEdit field on this function here:

    Qt Code:
    1. void teacherChatMain::returnPressedFunc()
    2. {
    3. QString text = lineEdit->text(); //allways returns ""
    4. if (text.isEmpty())
    5. return;
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    here is my constructor: (this is a plugin, I'll post 1st the mainWindow code then the plug in code)

    //MainWindow code

    bool mainWindow::instantiateTeacherChatPlugin( QObject * plugin )
    {
    iTChat = qobject_cast<ITeacherChat *>( plugin );
    if(iTChat)
    {
    iTChat->initialize();
    iTChat->setParentWidget(this);
    m_iTChat = plugin;
    chatTimerPull = new QTimer();
    return true;
    }
    return false;
    }

    Qt Code:
    1. void teacherChatMain::initialize( void )
    2. {
    3. scrollArea = new QScrollArea();
    4. }
    5.  
    6. void teacherChatMain::startWorking( void )
    7. {
    8. winChatWidget = new QWidget;
    9. winChatWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    10. winChatWidget->setMaximumWidth(350);
    11.  
    12. gridLayout = new QGridLayout;
    13.  
    14. stuNameLbl = new QLabel("",winChatWidget);
    15. stuNameLbl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    16. stuNameLbl->setMinimumSize(368,20);
    17.  
    18. gridLayout->addWidget(stuNameLbl, 0, 0, 0, 1);
    19.  
    20. closeBt = new QPushButton(winChatWidget);
    21. closeBt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    22. closeBt->setFixedSize(20, 20);
    23.  
    24. closeBt->setIcon(QIcon(":/resources/cancelar.png"));
    25. closeBt->setIconSize(QSize(16, 16));
    26.  
    27. gridLayout->addWidget(closeBt, 0, 2);
    28.  
    29. textEdit = new QTextEdit(winChatWidget);
    30. textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    31. textEdit->setFocusPolicy(Qt::NoFocus);
    32. textEdit->setMinimumSize(394,450);
    33.  
    34. gridLayout->addWidget(textEdit, 1, 0, 1, 1);
    35.  
    36. messageLbl = new QLabel(tr("Mensagem: "),winChatWidget);
    37. messageLbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    38. messageLbl->setMinimumWidth(80);
    39. messageLbl->setMaximumWidth(80);
    40. gridLayout->addWidget(messageLbl, 2, 0);
    41.  
    42. lineEdit = new QLineEdit(winChatWidget);
    43. messageLbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    44. lineEdit->setFocusPolicy(Qt::StrongFocus);
    45. lineEdit->setMinimumSize(307,20);
    46. gridLayout->addWidget(lineEdit, 2, 1);
    47.  
    48. closeBt->setVisible(false);
    49. stuNameLbl->setVisible(false);
    50.  
    51. tableFormat.setBorder(0);
    52.  
    53. connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressedFunc()));
    54.  
    55.  
    56. winChatWidget->setLayout(gridLayout);
    57. setTeacherName(_parent->getTeacherName());
    58.  
    59. setActive(false);
    60.  
    61. connect(this, SIGNAL(newMessage(QString,QString)),
    62. this, SLOT(appendMessage(QString,QString)));
    63.  
    64. stGridDlg = new studentsGridDialog(this, studentsScrollArea,_parent->getLoggedStudents(), _parent->getTeacherName(), windowChatScrollArea);
    65. QObject::connect(stGridDlg, SIGNAL(newMessageReceived()), this, SLOT(newMessageReceived()));
    66. connect(this, SIGNAL(returnPressedMsg(QString, QString)), stGridDlg, SIGNAL(returnPressedSignal(QString, QString)));
    67.  
    68.  
    69. contentsLayout->addWidget(studentsScrollArea,0,0);
    70. contentsLayout->addWidget(winChatWidget,0,1);
    71.  
    72. scrollArea->setLayout(contentsLayout);
    73. }
    To copy to clipboard, switch view to plain text mode 

    Please can some one help me? I'm about to try my next step which is throwing the computer out of the window!!!


    Added after 6 minutes:


    oh and when I was using the .ui form file when debugging I noticed the when I created the class object It saved it to a X spot on the memory, when I pressed "enter" on the lineedit its "this" position on the memory was different... back on the .cpp when I created the object I could access the correct object! ... really weird.
    Last edited by rickrvo; 8th April 2011 at 18:06.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: weird QLineEdit bug that won't show its text...

    Make sure there are no other signals connected that would make the line edit clear its contents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    rickrvo (12th April 2011)

  4. #3
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    nop.. :\ in fact.. If i start the QLineEdit with "blah" for example... after the QString text = lineEdit->text() (and after changing the lineEdit on the GUI to something else) it returns "blah" to the text string...
    Last edited by rickrvo; 8th April 2011 at 19:16.

  5. #4
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    oh and also lineEdit->clear(); does nothing on the GUI but clears the text value.. and if i connect(lineEdit, SIGNAL(textEdited(QString)), this, SLOT(debug(QString)));

    Qt Code:
    1. void teacherChatMain::debug(QString text)
    2. {
    3. QMessageBox::information(NULL,"debug","changed text = "+text);
    4. QMessageBox::information(NULL,"debug","lineEdit->text() = "+lineEdit->text());
    5. }
    To copy to clipboard, switch view to plain text mode 

    it show the correct edited text on the string text and nothing or If I set something on the constructor like lineEdit->setText("blah"); it shows "blah"..

    Now I can change the text within this function with lineEdit->setText(text); but this wasn't supposed to happen right?
    Last edited by rickrvo; 11th April 2011 at 14:43.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: weird QLineEdit bug that won't show its text...

    Make sure you don't have multiple variables with the same name shadowing each other and rebuild the whole project to be sure no stale files are left around.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    rickrvo (12th April 2011)

  8. #6
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    the variables are unique and I've tried rebuilding the whole project, manually erasing tempo files from the project folder and still same bug..

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: weird QLineEdit bug that won't show its text...

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    rickrvo (12th April 2011)

  11. #8
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    I tried to create a minimal example to reproduce the problem but creating a new project and trying to re-create this problem isn't working because the qlineedit works as it should with an simpler example...

    I'm also having trouble with every object on that widget, not only the QLineEdit but also with a label and a textedit... all of which are created inside the main cpp of the plugin...

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: weird QLineEdit bug that won't show its text...

    Change the filename of the file causing you problems and rebuild the project. If it builds then it means you are working with a wrong file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    rickrvo (12th April 2011)

  14. #10
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    it doesn't build. Says that the file is missing. I'm working with the right file, the changes that I've mentioned where made within the main cpp of the plugin, and visible on the GUI.

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

    Default Re: weird QLineEdit bug that won't show its text...

    I tried to create a minimal example to reproduce the problem but creating a new project and trying to re-create this problem isn't working because the qlineedit works as it should with an simpler example...
    Add functionality to that project bit by bit, until you get the same behavior, or probably until you notice your error since the last bit you added before the error is there, is the bit that created it.
    ==========================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.

  16. The following user says thank you to high_flyer for this useful post:

    rickrvo (12th April 2011)

  17. #12
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    Quote Originally Posted by high_flyer View Post
    Add functionality to that project bit by bit, until you get the same behavior, or probably until you notice your error since the last bit you added before the error is there, is the bit that created it.
    I'm sorry but I don't get it... what do you mean by adding bit by bit?

  18. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: weird QLineEdit bug that won't show its text...

    Add pieces of code from your real project into the dummy project until the dummy project stops working. Then the last added piece is the cause of your problems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    rickrvo (12th April 2011)

  20. #14
    Join Date
    Dec 2010
    Posts
    71
    Thanks
    26
    Platforms
    Windows

    Default Re: weird QLineEdit bug that won't show its text...

    Fixed it! There was another plugin that was calling startWorking() of this plugin... so I was working with a part of the memory on the GUI and it was saving the information on the 1st created objects of the 1st call of startWorking()...

    thanks!

Similar Threads

  1. Weird text input problem
    By zeldaknight in forum Qt Programming
    Replies: 6
    Last Post: 10th July 2010, 22:19
  2. I cannot get the string from QLineEdit->text()!
    By MIH1406 in forum Qt Programming
    Replies: 0
    Last Post: 3rd June 2010, 12:26
  3. QLineEdit text orientation
    By emrares in forum Qt Programming
    Replies: 7
    Last Post: 15th September 2009, 07:25
  4. QLineEdit, draw only text
    By Radagast in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2009, 12:15
  5. QLineEdit and background text
    By SnarlCat in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2009, 23:17

Tags for this Thread

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.