Results 1 to 5 of 5

Thread: Creating and Using Qdialog

  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Creating and Using Qdialog

    I have created a modal dialog and it responds to the 'ok' and 'cancel' buttons fine. My main issue is that when I attempt to put code to access the other fields in the dialog I get some errors:

    Qt Code:
    1. //popup for modal dialog:
    2. void PulseMain::popupmodal() {
    3.  
    4. //create a dialog box:
    5. DialogLogin dlg(this);
    6.  
    7.  
    8. //do something once we click OK:
    9. if( dlg.exec() == QDialog::Accepted ) {
    10.  
    11. //initialize a place to put our login information:
    12. var_login login;
    13.  
    14. // Extract the information from the dialog
    15. login.username = dlg.userid->text();
    16. login.password = dlg.password->text();
    17.  
    18.  
    19.  
    20. QMessageBox::warning( this, "Dialog results!", "We clicked OK!");
    21.  
    22. //else do something when we click cancel:
    23. } else {
    24.  
    25. QMessageBox::warning( this, "Dialog results!", "We canceled it!");
    26.  
    27. }
    28.  
    29.  
    30.  
    31.  
    32. //dlg.exec();
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

    everything works fine when the following lines are removed:

    Qt Code:
    1. login.username = dlg.userid->text();
    2. login.password = dlg.password->text();
    To copy to clipboard, switch view to plain text mode 

    when the lines are there I get the following error message when compiling the program:

    ui_dialog_login.h:29: error: 'QLineEdit* Ui_DialogLogin::userid' is inaccessible
    calculatorform.cpp:48: error: within this context
    ui_dialog_login.h:30: error: 'QLineEdit* Ui_DialogLogin:assword' is inaccessible
    calculatorform.cpp:49: error: within this context
    so it seems that I am using the wrong route to access the text items in the dialog. I am sure that its something simple that I am missing that would make this work properly. Anyone have an idea?

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating and Using Qdialog

    Qt Code:
    1. userid;
    2. password;
    To copy to clipboard, switch view to plain text mode 
    are declared and defined in UI namespace so probably you have to access them using your UI nampespace or something like that.

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

    tpf80 (14th March 2007)

  4. #3
    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: Creating and Using Qdialog

    Quote Originally Posted by vermarajeev View Post
    are declared and defined in UI namespace so probably you have to access them using your UI nampespace or something like that.
    ... and it would be better if you had a public function in DialogLogin, which return the login informations in a var_login type. So the elements could stay private and if you change the dialog you just have to alter his own sources.

    Lykurg

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

    tpf80 (14th March 2007)

  6. #4
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Creating and Using Qdialog

    Thanks you both, I accessed the UI namespace with in DialogLogin to get at the information, and then I was able to use a public function within DialogLogin to pass the var_login type to the parent window.

    Does this mean that when you click "ok" or "cancel" and the dialog disappears from view, that it still is actually there, just you can't see it? or is it destroyed?

  7. #5
    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: Creating and Using Qdialog

    Quote Originally Posted by tpf80 View Post
    Does this mean that when you click "ok" or "cancel" and the dialog disappears from view, that it still is actually there, just you can't see it?
    right,
    or is it destroyed?
    the dialog is destroyed at the end of the scope. In your case after the finishing brace of PulseMain:opupmodal().


    Lykurg

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.