Results 1 to 2 of 2

Thread: passing arguments from command line to QT application

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default passing arguments from command line to QT application

    Hello!

    I've got problem with passing arguments from command line to application:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8.  
    9. w.show();
    10.  
    11. w.myVariable = QString(argv[1]).toInt();
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    myVariable is public. And it has very weird values. When I pass that argument to function which is printing that value on console at startup everything is ok. How can I do it?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: passing arguments from command line to QT application

    Use QCoreAppliction::arguments() instead of argv.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Tomasz (8th September 2010)

Similar Threads

  1. Replies: 3
    Last Post: 23rd February 2010, 05:33
  2. Internal Qt4 Standards for Command Line Arguments
    By wswartzendruber in forum Newbie
    Replies: 3
    Last Post: 8th October 2009, 08:16
  3. QTest and Command Line Arguments
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2009, 13:32
  4. Retrieving command line arguments inside a Qt application
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2009, 15:28
  5. Passing Command Line Values?
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 29th March 2006, 09:26

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.