Results 1 to 6 of 6

Thread: Retrieving command line arguments inside a Qt application

  1. #1
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Retrieving command line arguments inside a Qt application

    We have the code:

    Qt Code:
    1. #include <QApplication>
    2. #include <QDialog>
    3. #include <QProcess>
    4. #include <cstdlib>
    5.  
    6. #include "dialog.h"
    7.  
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication app(argc, argv);
    12.  
    13. Dialog dialog;
    14.  
    15. dialog.show();
    16.  
    17. if(app.exec()!= 0)
    18. return EXIT_FAILURE;
    19. }
    To copy to clipboard, switch view to plain text mode 


    How can we retrieve the command line arguments, inside the dialog code (declared in dialog.h as "class Dialog: public QDialog, Ui:: Dialog")?


    Thanks.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving command line arguments inside a Qt application

    add a public function in Dialog class which takes char* argument and pass the argv to it from main function

  3. #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: Retrieving command line arguments inside a Qt application

    Hi,

    simply use QCoreApplication::arguments () via the qApp pointer but be aware that Qt removes command line arguments that it recognizes!

    Lykurg

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

    talk2amulya (14th February 2009)

  5. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving command line arguments inside a Qt application

    thanks for the valuable post man, but what do u mean when u say QT recognizes the argument..what kind of argument can it recognize

  6. #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: Retrieving command line arguments inside a Qt application

    Hey, the known arguments are listed at QApplication::QApplication ( int & argc, char ** argv ). There's also the warning.

    Lykurg

  7. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving command line arguments inside a Qt application

    oh..so u meant OPTIONS that QApplication recognizes..yeh, in that way its true...thanks for info!

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.