Results 1 to 3 of 3

Thread: C++/Qt5.10.1 - Getting returned data from QDialog

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt5.10.1 - Getting returned data from QDialog

    Hello,

    I've sort of got it working, but still missing something.
    As you can see the results I'm getting from "if (dlg.exec() == QDialog::Accepted)" are
    always from the reject choice.
    Help please.

    Regards

    Qt Code:
    1. Results:-
    2. reject "returnded - ok" - OK button
    3. reject "returnded - rej" - cancel button
    4. reject "returnded - rej" - Dialog 'X' button
    5. reject "returnded - rej" - menu exit
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. calling Dialog:-
    2. divideoptionsdlg dlg(passedData, parent);
    3. QObject::connect( &dlg, SIGNAL(returnData(QString)), this, SLOT(gotReturnedData(QString)) );
    4. if (dlg.exec() == QDialog::Accepted)
    5. {
    6. qDebug() << "accept " << returned; //ok button
    7. }
    8. else
    9. {
    10. qDebug() << "reject " << returned; //cancel button
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. callled Dialog:-
    2. B1->setGeometry( this->width() / 2, this->height() - 30, (this->width() / 2) - 5, 30 );
    3. B1->addButton(tr("OK"), QDialogButtonBox::AcceptRole);
    4. B1->addButton(tr("Cancel"),QDialogButtonBox::RejectRole);
    5. QObject::connect( B1, SIGNAL(accepted()), this, SLOT(onOKclickedSlot()) );
    6. QObject::connect( B1, SIGNAL(rejected()), this, SLOT(reject()) );
    7.  
    8. void divideoptionsdlg::onOKclickedSlot()
    9. {
    10. QString data = "returnded - ok";
    11. emit returnData(data);
    12. this->close();
    13. }
    14.  
    15. divideoptionsdlg::~divideoptionsdlg()
    16. {
    17. QString data = "returnded - rej";
    18. emit returnData(data);
    19. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: C++/Qt5.10.1 - Getting returned data from QDialog

    In onOKclickedSlot() call accept() not close();

  3. The following user says thank you to ChrisW67 for this useful post:

    jimbo (11th April 2018)

  4. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt5.10.1 - Getting returned data from QDialog [Solved]

    Quote Originally Posted by ChrisW67 View Post
    In onOKclickedSlot() call accept() not close();
    Many thanks

    Regards

Similar Threads

  1. Replies: 2
    Last Post: 16th June 2010, 15:42
  2. Replies: 5
    Last Post: 1st March 2010, 15:55
  3. How to return a lot of data from a QDialog
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 12:10
  4. Validate Data in QDialog
    By jcraig in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2007, 15:49
  5. QDialog and QMainWindow Data Transfer
    By Ahmad in forum Qt Programming
    Replies: 12
    Last Post: 6th May 2007, 07:02

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.