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:
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: