PDA

View Full Version : weird QLineEdit bug that won't show its text...



rickrvo
8th April 2011, 17:06
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:



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;
}



void teacherChatMain::initialize( void )
{
scrollArea = new QScrollArea();
}

void teacherChatMain::startWorking( void )
{
winChatWidget = new QWidget;
winChatWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
winChatWidget->setMaximumWidth(350);

gridLayout = new QGridLayout;

stuNameLbl = new QLabel("",winChatWidget);
stuNameLbl->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
stuNameLbl->setMinimumSize(368,20);

gridLayout->addWidget(stuNameLbl, 0, 0, 0, 1);

closeBt = new QPushButton(winChatWidget);
closeBt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
closeBt->setFixedSize(20, 20);

closeBt->setIcon(QIcon(":/resources/cancelar.png"));
closeBt->setIconSize(QSize(16, 16));

gridLayout->addWidget(closeBt, 0, 2);

textEdit = new QTextEdit(winChatWidget);
textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
textEdit->setFocusPolicy(Qt::NoFocus);
textEdit->setMinimumSize(394,450);

gridLayout->addWidget(textEdit, 1, 0, 1, 1);

messageLbl = new QLabel(tr("Mensagem: "),winChatWidget);
messageLbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
messageLbl->setMinimumWidth(80);
messageLbl->setMaximumWidth(80);
gridLayout->addWidget(messageLbl, 2, 0);

lineEdit = new QLineEdit(winChatWidget);
messageLbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
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);

connect(this, SIGNAL(newMessage(QString,QString)),
this, SLOT(appendMessage(QString,QString)));

stGridDlg = new studentsGridDialog(this, studentsScrollArea,_parent->getLoggedStudents(), _parent->getTeacherName(), windowChatScrollArea);
QObject::connect(stGridDlg, SIGNAL(newMessageReceived()), this, SLOT(newMessageReceived()));
connect(this, SIGNAL(returnPressedMsg(QString, QString)), stGridDlg, SIGNAL(returnPressedSignal(QString, QString)));


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:

wysota
8th April 2011, 17:06
Make sure there are no other signals connected that would make the line edit clear its contents.

rickrvo
8th April 2011, 18:10
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...

rickrvo
11th April 2011, 13:31
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)));


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?

wysota
11th April 2011, 13:45
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.

rickrvo
11th April 2011, 14:46
the variables are unique and I've tried rebuilding the whole project, manually erasing tempo files from the project folder and still same bug..

wysota
11th April 2011, 14:48
Please provide a minimal compilable example reproducing the problem.

rickrvo
11th April 2011, 16:31
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...

wysota
11th April 2011, 17:13
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.

rickrvo
11th April 2011, 17:20
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.

high_flyer
11th April 2011, 17:20
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.

rickrvo
11th April 2011, 18:08
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?

wysota
11th April 2011, 18:14
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.

rickrvo
12th April 2011, 13:57
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!