Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41

Thread: closing a dialog

  1. #21
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Still does not bring up a new dialog

    Qt Code:
    1. class webapp : public QDialog {
    2. Q_OBJECT
    3. public:
    4. webapp(QDialog* parent);
    5. .............
    6. void test::web() {
    7. webapp::webapp(*parent);
    8. }
    9. webapp::webapp(QDialog* parent) {
    10. QDialog *web = new webapp(this);
    11. web->show();
    12. view = new QWebView(web);
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Please find the attached example.
    Attached Files Attached Files
    It's nice to be important but it's more important to be nice.

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

    chrisb123 (25th October 2009)

  4. #23
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    thanks, i'll have to study this tonight at work

  5. #24
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    I dont have main because it is a plasma widget
    It's setup like the example you gave me

    Qt Code:
    1. mum::mum(QObject *parent, const QVariantList &args)
    2. : Plasma::Applet(parent, args),
    3. m_svg(this),
    4. m_icon("document"),
    5. m_webapp(NULL),
    6. m_setapp(NULL)
    7. {
    8. m_webapp = new webapp(this);
    9. m_setapp = new setapp();
    10. }
    11. void mum::settings() {
    12. m_setapp->show();
    13.  
    14. }
    15. void mum::web() {
    16. m_webapp->show();
    17. }
    To copy to clipboard, switch view to plain text mode 

    setapp works as expected
    webapp gives the following error

    Qt Code:
    1. mum.cpp: In constructor 'mum::mum(QObject*, const QVariantList&)':
    2. mum.cpp:30: error: no matching function for call to 'webapp::webapp(mum* const)'
    3. webapp.h:33: note: candidates are: webapp::webapp(QWidget*)
    To copy to clipboard, switch view to plain text mode 
    Last edited by chrisb123; 25th October 2009 at 12:14.

  6. #25
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Looks like Plasma::Applet does not inherit QWidget. OK, then you can't have that as parent, just pass NULL as parent and delete webapp in your destructor.
    It's nice to be important but it's more important to be nice.

  7. #26
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    how would i make it show the exisitng m_webapp from m_setapp?

  8. #27
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Either create m_webapp inside m_setapp or have m_setapp emit a signal and connect that to the show-slot of m_webapp.
    It's nice to be important but it's more important to be nice.

  9. #28
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Quote Originally Posted by axeljaeger View Post
    Either create m_webapp inside m_setapp or have m_setapp emit a signal and connect that to the show-slot of m_webapp.
    I'll have to read up on that

    I want the widget to not create the web app utill its called for e.g.
    Qt Code:
    1. void mum::web() {
    2. if ( ! m_webapp ) {
    3. m_webapp = new webapp(NULL);
    4. }
    5. m_webapp->show();
    6. }
    To copy to clipboard, switch view to plain text mode 
    How do I destroy m_webapp after closing it?

  10. #29
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Just delete it in the destructor. (once in the lifetime of your application).
    It's nice to be important but it's more important to be nice.

  11. #30
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    delete it like this?
    Qt Code:
    1. webapp::~webapp(){
    2. delete this;
    3. }
    To copy to clipboard, switch view to plain text mode 
    doesnt seem to delete m_webapp

    also emitting the signal and connecting to it
    what am I doing wrong?

    Qt Code:
    1. m_setapp = new SetApp(NULL);
    2. connect(m_setapp, SIGNAL(showeb()), this SLOT(web()));
    3. }
    4. void mum::web() {
    5. m_webapp->show();
    6. }
    7. ..................
    8. connect( pushButton_node, SIGNAL( clicked() ), this, SLOT( node() ) );
    9. }
    10. void SetApp::node() {
    11. emit showeb(); //this pushbutton code work
    To copy to clipboard, switch view to plain text mode 
    or can I do I connect to a slot in a different class?
    Last edited by chrisb123; 25th October 2009 at 14:51.

  12. #31
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    delete this in a destructor is an infinite recursion.

    delete calls the destructor. It is basically calling a method within itself. This will not work.


    Regarding your signal & slots connection: What does not work? Do you get any warnings in the console? Do all connect-statements return true?
    It's nice to be important but it's more important to be nice.

  13. #32
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Quote Originally Posted by axeljaeger View Post
    delete this in a destructor is an infinite recursion.

    delete calls the destructor. It is basically calling a method within itself. This will not work.
    closing it does not destroy it, it just hides it

    Regarding your signal & slots connection: What does not work? Do you get any warnings in the console? Do all connect-statements return true?
    syntax error, i missed the , after this
    it works as expected
    Last edited by chrisb123; 25th October 2009 at 15:19.

  14. #33
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Quote Originally Posted by chrisb123 View Post
    closing it does not destroy it, it just hides it
    What do you want to tell me?
    It's nice to be important but it's more important to be nice.

  15. #34
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Think I've worked it out
    I want the plasmoid to display a seperate dialog and QWebView when requested.
    I dont want the QWebView to be always loaded but hidden

    So currently it does the following, From my understadning

    1. when the plasmoid starts it creates the constructor which just creates the dialog
    2. when i select the item to show the dialog I use showEvent to create a QWebView and display the page.
    3. When I close the dialog I use closeEvent to delete the QWebView

    What can I use as profiling software?

  16. #35
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Why on earth do you want to create the webView in the showEvent and destroy it when it gets closed? Just do it like anyone else: Create it in the constructor let it Qt destroy when necessary. Dont try to be too clever, keep it simple stupid, trust Qt.

    You can use either valgrind or oprofile for profiling. But if there is already need for profiling, then your computer has a problem.
    It's nice to be important but it's more important to be nice.

  17. #36
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: closing a dialog

    Quote Originally Posted by chrisb123 View Post
    I made a plasma app that opens a settings dialog
    I'm trying to close a dialog with a close button
    If I open it like this

    Qt Code:
    1. void test::settings() {
    2. myQtApp *dialog = new myQtApp;
    3. dialog->show();
    4. }
    To copy to clipboard, switch view to plain text mode 

    How can i close it like this

    Qt Code:
    1. myQtApp::myQtApp(QWidget *parent)
    2. {
    3. setupUi(this);
    4. connect( pushButton_close, SIGNAL( clicked() ), this, SLOT( close() ) );
    5. }
    6. void myQtApp::close() {
    7. QMessageBox::about(this,"close",
    8. "this shold close the dialog");
    9. }
    To copy to clipboard, switch view to plain text mode 
    Didn't read up all if you actually fixed your problem already but:
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    this would solve your problem with deleting dialog.

  18. #37
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Quote Originally Posted by RSX View Post
    Didn't read up all if you actually fixed your problem already but:
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    this would solve your problem with deleting dialog.
    That works but how do I test if dialog has been deleted or not, I only want to have one created at any one time

  19. #38
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: closing a dialog

    I think it's deleted when you close the dialog. Qt uses to do a lot of hard work for you

    Well, if so, you can delete it manually.
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    4. delete dialog;
    5. dialog = 0;
    To copy to clipboard, switch view to plain text mode 

    What I do is to create the dialog on the stack. So it will be deleted for sure when it's out of scope. But I do it with small and temporary dialogs.

    Qt Code:
    1. myQtApp dialog(this);
    2. dialog.setAttribute(Qt::WA_DeleteOnClose);
    3. dialog.show();
    To copy to clipboard, switch view to plain text mode 

  20. #39
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    My application is a plasma widget so 99.99% of the time its just the one widget, there is no reason to have anything else just waiting, hidden, invisible or not shown.

    When I use this code
    Qt Code:
    1. m_setapp = new SetApp(this);
    To copy to clipboard, switch view to plain text mode 
    I get this error while compiling
    Qt Code:
    1. mum.cpp: In member function 'void mum::settings()':
    2. mum.cpp:75: error: no matching function for call to 'SetApp::SetApp(mum* const)'
    3. myqtapp.h:34: note: candidates are: SetApp::SetApp(QWidget*)
    4. myqtapp.h:29: note: SetApp::SetApp(const SetApp&)
    To copy to clipboard, switch view to plain text mode 
    But this works ok
    Qt Code:
    1. m_setapp = new SetApp(NULL);
    To copy to clipboard, switch view to plain text mode 

    From what I can tell it's not deleted when it's closed, I have to manually delete it when its closed, then create it again when required

  21. #40
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Right, you have to delete it yourself when you close the application.

    But again: Dont try to be to clever. Get your application up and running and dont bother too much in saving memory when you are not know what you are actually doing. Keeping the dialog in memory will not hurt very much. I'd keep it there so it gets shown faster the second time I open it.
    It's nice to be important but it's more important to be nice.

  22. The following user says thank you to axeljaeger for this useful post:

    chrisb123 (27th October 2009)

Similar Threads

  1. Closing a dialog using a button
    By srohit24 in forum Qt Programming
    Replies: 5
    Last Post: 21st July 2009, 06:57
  2. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 11:10
  3. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 18:04
  4. Replies: 9
    Last Post: 13th August 2008, 19:07
  5. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 11:35

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.