PDA

View Full Version : Dialog



dragon
22nd July 2011, 16:33
Hello anyone,

Iám using Qt 4.7 on Windows XP.
Iám using QtCreator.
I have made severall applications with no problems at all.

I have a mainwindow with a dialog.
I call the dialog wich contains a QTableWidget with items.
I want to return item value from the table and put the the value into the mainwindow lineEdit.
My problem is that when i execute the dialog through a pushbutton the dialog appears but when i click on the ok pushbutton on the dialog it hangs and doesn't return to the mainwindow.

Mainwindow.cpp


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->matvoorPb, SIGNAL(clicked()), this, SLOT(test()));
etc....
}

void MainWindow::test(){
matDialog dlg(this);
if(dlg.exec() == QDialog::Accepted){
item = new QTableWidgetItem();
item = dlg.matTable->currentItem();
QString mat = item->text();
ui->matvoorLe->setText(mat);
}
}



Thanks in advance.

Santosh Reddy
22nd July 2011, 19:58
void MainWindow::test(){
matDialog dlg(this);
if(dlg.exec() == QDialog::Accepted){
item = new QTableWidgetItem(); //instant memory leak, remove this statement
item = dlg.matTable->currentItem();
QString mat = item->text(); //Check item for non-zero
ui->matvoorLe->setText(mat);
}
}

dragon
22nd July 2011, 21:35
Hello

I try your suggestion but with no luck.

I think wat the problem is.
I comment out some lines like this.


void MainWindow::test(){
matDialog dlg(this);
if(dlg.exec() == QDialog::Accepted){
// dlg.matTable->currentItem();
// if(!item->text().isEmpty()){
// QString mat = item->text();
// ui->matvoorLe->setText(mat);
// }
}
}

This works no problem.
The line dlg.matTable->currentItem(); is the problem that the Dialog hangs.
The matTable crashes the Dialog.
matTable is in the Dialog a QTableWidget.
If i get rid of the comment the line dlg.matTable->currentItem(); its hangs.

Thanks in advance.

Lykurg
22nd July 2011, 21:46
making matTable public isn't the best idea. So what about creating a getter method in the dialog which returns the text of current item. see if that works for you.

dragon
22nd July 2011, 22:04
Hello,

Can you give a example code of this getter method in the Dialog.

Thanks in advance

Santosh Reddy
3rd August 2011, 09:04
I want to return item value from the table and put the the value into the mainwindow lineEdit.
As I see you already have a custom dialog, so why not emit required signals from it, and connect to them from mainwindow. Just emits the signals from QDialog before closing