Results 1 to 7 of 7

Thread: getting data from a Dialog

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default getting data from a Dialog

    Hi
    I'm using public member-functions to get data from a called Dialog.
    Qt Code:
    1. #ifndef A_H
    2. #define A_H
    3.  
    4. #include <QtGui/QDialog>
    5.  
    6. namespace Ui {
    7. class a;
    8. }
    9.  
    10. class a : public QDialog {
    11. Q_OBJECT
    12. public:
    13. a(QWidget *parent = 0);
    14. ~a();
    15. QString getA();
    16. protected:
    17. void changeEvent(QEvent *e);
    18. private:
    19. Ui::a *m_ui;
    20. };
    21.  
    22. #endif // A_H
    To copy to clipboard, switch view to plain text mode 

    Calling the Dialog ...
    Qt Code:
    1. void Dialog::calla()
    2. {
    3. a x;
    4. x.exec();
    5. ui->a_lineEdit->setText(x.getA());
    6. }
    To copy to clipboard, switch view to plain text mode 

    Could someone point me other ways to do this!

    Thanks

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: getting data from a Dialog

    I think you have chosen the best way to obtain data from a class; by using a getter function.

    However, since you seem to want to synchronize the text in two widgets, you can consider connecting a textChanged() signal from your dialog to the lineEdit's setText() slot. In your case that wouldn't really reduce your code, though.
    Last edited by franz; 21st August 2009 at 06:58. Reason: updated contents
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

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

    graciano (21st August 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: getting data from a Dialog

    And if i want this working the opposite direction?
    Let's say i want that objects created from class a get some data from de base class.
    This is a constructor issue ... isn'it?
    Qt Code:
    1. #include "a.h"
    2. #include "ui_a.h"
    3.  
    4. a::a(QWidget *parent) :
    5. QDialog(parent),
    6. m_ui(new Ui::a)
    7. {
    8. m_ui->setupUi(this);
    9. m_ui->label.setText("data from the calling dialog!?!");
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. #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: getting data from a Dialog

    read about setter and getter functions. In your case it would be like:

    Qt Code:
    1. class a : public QDialog {
    2. Q_OBJECT
    3. public:
    4. //...
    5. void setSomeThing(QString str);
    6.  
    7. };
    8.  
    9. void a::setSomeThing(QString str)
    10. {
    11. // if needed check the content of str
    12. ui->someLineEdit->setText(str);
    13. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: getting data from a Dialog

    yess ... but the content of that str is somewhere in other Dialog that called this one.
    Am i missing something obvious?

  7. #6
    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: getting data from a Dialog

    Quote Originally Posted by graciano View Post
    Am i missing something obvious?
    Yes ;-)

    Qt Code:
    1. void Dialog::calla()
    2. {
    3. a x;
    4. x.setSomeThing("foo bar");
    5. x.exec();
    6. ui->a_lineEdit->setText(x.getA());
    7. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to Lykurg for this useful post:

    graciano (21st August 2009)

  9. #7
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: getting data from a Dialog

    Wellll ... guess i need vacations.
    "I'll be back "

Similar Threads

  1. data rate transfer is decreasing in TCP connection
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:15
  2. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  3. Replies: 2
    Last Post: 23rd May 2007, 03:51
  4. Replies: 3
    Last Post: 17th May 2007, 13:50

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.