Results 1 to 6 of 6

Thread: Dialog

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Dialog

    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
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. connect(ui->matvoorPb, SIGNAL(clicked()), this, SLOT(test()));
    7. etc....
    8. }
    9.  
    10. void MainWindow::test(){
    11. matDialog dlg(this);
    12. if(dlg.exec() == QDialog::Accepted){
    13. item = new QTableWidgetItem();
    14. item = dlg.matTable->currentItem();
    15. QString mat = item->text();
    16. ui->matvoorLe->setText(mat);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Dialog

    Qt Code:
    1. void MainWindow::test(){
    2. matDialog dlg(this);
    3. if(dlg.exec() == QDialog::Accepted){
    4. item = new QTableWidgetItem(); //instant memory leak, remove this statement
    5. item = dlg.matTable->currentItem();
    6. QString mat = item->text(); //Check item for non-zero
    7. ui->matvoorLe->setText(mat);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dialog

    Hello

    I try your suggestion but with no luck.

    I think wat the problem is.
    I comment out some lines like this.
    Qt Code:
    1. void MainWindow::test(){
    2. matDialog dlg(this);
    3. if(dlg.exec() == QDialog::Accepted){
    4. // dlg.matTable->currentItem();
    5. // if(!item->text().isEmpty()){
    6. // QString mat = item->text();
    7. // ui->matvoorLe->setText(mat);
    8. // }
    9. }
    10. }
    11.  
    12. This works no problem.
    13. The line dlg.matTable->currentItem(); is the problem that the Dialog hangs.
    14. The matTable crashes the Dialog.
    15. matTable is in the Dialog a QTableWidget.
    16. If i get rid of the comment the line dlg.matTable->currentItem(); its hangs.
    17.  
    18. Thanks in advance.
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Dialog

    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.

  5. #5
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dialog

    Hello,

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

    Thanks in advance

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Dialog

    Quote Originally Posted by dragon
    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

Similar Threads

  1. How to access objects of parent Dialog from Child Dialog .
    By ranjit.kadam in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 06:39
  2. Replies: 0
    Last Post: 5th October 2010, 07:41
  3. closing child dialog closes parent dialog
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 19:46
  4. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01
  5. Dialog to Dialog communication
    By jjbabu in forum Qt Tools
    Replies: 1
    Last Post: 1st October 2008, 10:54

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.