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:
Code:
void teacherChatMain::returnPressedFunc()
{
QString text
= lineEdit
->text
();
//allways returns "" if (text.isEmpty())
return;
...
}
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;
}
Code:
void teacherChatMain::initialize( void )
{
}
void teacherChatMain::startWorking( void )
{
winChatWidget->setMaximumWidth(350);
stuNameLbl
= new QLabel("",winChatWidget
);
stuNameLbl->setMinimumSize(368,20);
gridLayout->addWidget(stuNameLbl, 0, 0, 0, 1);
closeBt->setFixedSize(20, 20);
closeBt
->setIcon
(QIcon(":/resources/cancelar.png"));
closeBt
->setIconSize
(QSize(16,
16));
gridLayout->addWidget(closeBt, 0, 2);
textEdit->setFocusPolicy(Qt::NoFocus);
textEdit->setMinimumSize(394,450);
gridLayout->addWidget(textEdit, 1, 0, 1, 1);
messageLbl
= new QLabel(tr
("Mensagem: "),winChatWidget
);
messageLbl->setMinimumWidth(80);
messageLbl->setMaximumWidth(80);
gridLayout->addWidget(messageLbl, 2, 0);
lineEdit->setFocusPolicy(Qt::StrongFocus);
lineEdit->setMinimumSize(307,20);
gridLayout->addWidget(lineEdit, 2, 1);
closeBt->setVisible(false);
stuNameLbl->setVisible(false);
tableFormat.setBorder(0);
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressedFunc()));
winChatWidget->setLayout(gridLayout);
setTeacherName(_parent->getTeacherName());
setActive(false);
stGridDlg = new studentsGridDialog(this, studentsScrollArea,_parent->getLoggedStudents(), _parent->getTeacherName(), windowChatScrollArea);
QObject::connect(stGridDlg,
SIGNAL(newMessageReceived
()),
this,
SLOT(newMessageReceived
()));
contentsLayout->addWidget(studentsScrollArea,0,0);
contentsLayout->addWidget(winChatWidget,0,1);
scrollArea->setLayout(contentsLayout);
}
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. :confused:
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.
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...
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)));
Code:
void teacherChatMain
::debug(QString text
) {
QMessageBox::information(NULL,
"debug",
"changed text = "+text
);
QMessageBox::information(NULL,
"debug",
"lineEdit->text() = "+lineEdit
->text
());
}
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?
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.
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..
Re: weird QLineEdit bug that won't show its text...
Please provide a minimal compilable example reproducing the problem.
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...
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.
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.
Re: weird QLineEdit bug that won't show its text...
Quote:
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.
Re: weird QLineEdit bug that won't show its text...
Quote:
Originally Posted by
high_flyer
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?
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.
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!