Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Show and use a custom dialog from within a widget or mainwindow
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Show and use a custom dialog from within a widget or mainwindow

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinb
    wrote on last edited by
    #1

    Hi all,
    I have a 'stupid' question about using a costum dialog from within a widget/mainwindow.
    I have a widget with a pushbutton, when i push the button i want to show a custom dialog and use its input to work with inside the first widget.
    When i try this from within 'main.cpp' it works without a problem, but when i use the same from within the widget nothing seems to happen.
    Does anybody know what im doing wrong or better, where i have to look for it?
    This seems to not work:
    @
    //filename is widget.cpp
    #include "dialog.h"
    void Widget::on_pushButton_clicked()
    {
    this.hide(); //works
    Dialog d; // doesnt work?
    d.show(); // doesnt work
    }
    @
    This works:
    @
    //filename is main.cpp
    #include "dialog.h"
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Dialog d; //works
    d.show(); //works
    return a.exec();
    }
    @

    I know that i can make a function within the main.cpp to get it work, but i want to use it from within the widget.cpp and not use the main.cpp for functions ed. Is this possible or is it a really stupid question?

    Thanks in advance,
    vinb.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You should not hide your main widget.

      You should call d.exec() on the dialog. This opens the new window as modal dialog, i.e. it blocks input to all other windows while it is open. exec() returns when the dialog is closed (either by accept() or by reject(). See the docs of "QDialog":http://doc.qt.nokia.com/4.7/qdialog.html for some more information.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        This looks a lot like another, "very recent discussion":http://developer.qt.nokia.com/forums/viewthread/4649/ here. You did "search before asking":http://www.catb.org/~esr/faqs/smart-questions.html#before, didn't you?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vinb
          wrote on last edited by
          #4

          Thanks both!
          And yes i've searched but with the wrong keywords i quess. :)
          Sorry, for wasting your time.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved