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. QInputDialog In Main
Forum Updated to NodeBB v4.3 + New Features

QInputDialog In Main

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.5k 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.
  • P Offline
    P Offline
    Praveenin_ece
    wrote on last edited by
    #1

    the Following is my code

    @#include <QtGui/QApplication>
    #include <QInputDialog>
    //#include "mydilog.h"
    #include <QDebug>

    int main(int argc,char* argv[])
    {

    QApplication app(argc, argv);
    bool ok;
    QString output;
      output = QInputDialog::getText(NULL, ("QInputDialog::getText()"),
                                                  ("User name:"), QLineEdit::Normal,
                                                   "test", &ok);
    qDebug() << "Ok == " << ok;
    qDebug() << "output == " << output;
    app.exec&#40;&#41;;
    

    }@

    How can i quit the Program on from main? i want the app.exec(); but on "Ok" Button click i want to quit from the Main.

    How can i Implement this

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on last edited by
      #2

      compare the output with "Text to Exit" and call exit() ?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        I'm not quite sure what "... i want the app.exec() ..." means but if you want to enter the event loop before exiting (for whatever reason) use a singleshot timer.
        @
        int main(int argc,char* argv[])
        {
        ...

        qDebug() << "Ok == " << ok;
        qDebug() << "output == " << output;
        
        if(ok == true)
            QTimer::singleShot(0, &app, SLOT(quit()));
        
        return app.exec(); 
        

        }
        @
        Otherwise just don't call QApplication::exec().
        @
        int main(int argc,char* argv[])
        {
        ...

        qDebug() << "Ok == " << ok;
        qDebug() << "output == " << output;
        
        if(ok == false)
            return app.exec();
        
        return 0; 
        

        }
        @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          [quote author="stuk" date="1328868151"]compare the output with "Text to Exit" and call exit() ?[/quote]

          QApplication::quit() and QApplication:exit() does nothing if there is no event loop running (ie. before QApplication::exec() is called).

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stukdev
            wrote on last edited by
            #5

            for exit() i mean the stdlib function.

            [quote author="Lukas Geyer" date="1328868453"][quote author="stuk" date="1328868151"]compare the output with "Text to Exit" and call exit() ?[/quote]

            QApplication::quit() and QApplication:exit() does nothing if there is no event loop running (ie. before QApplication::exec() is called).[/quote]

            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