Results 1 to 4 of 4

Thread: Passing Command line arguments to a Qt application in linux

  1. #1
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Passing Command line arguments to a Qt application in linux

    Hi all,

    I have a Qt application for which i have to pass some command line arguements to make it execute..is there any way to set the command line arguements programatically?

    How can i achieve this?Anyone, plz help me in this regard.............

    Is it possible to mention command line arguements while executing itself?

    Regards,
    Payal

  2. #2
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Command line arguments to a Qt application in linux

    Do you want to execute an application passing some arguments? Look at QProcess::start.
    Do you want to get arguments passed to your application? Look at QCoreApplication::arguments.

  3. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Passing Command line arguments to a Qt application in linux

    yes payal , you can pass arguments from cmd line,

    ex
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication app(argc, argv);
    4. QStringList args = app.arguments();
    5. if (args.count() != 2)
    6. {
    7.  
    8. std::cerr << "argument required" << endl;
    9. return 1;
    10. }
    11. myClass m; //ur class
    12. m.test(args[1]); //pass cmd argument as function argument.
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    hope it helpz
    Bala

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

    Ade Malsasa Akbar (13th November 2013)

  5. #4
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Command line arguments to a Qt application in linux

    Thanks alot Bala..............

    I am using QTCreator and i added command line arguements in Project settings.......So now its fine..........

    Regards,
    Payal

Similar Threads

  1. Internal Qt4 Standards for Command Line Arguments
    By wswartzendruber in forum Newbie
    Replies: 3
    Last Post: 8th October 2009, 08:16
  2. QTest and Command Line Arguments
    By ManuMies in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2009, 13:32
  3. Retrieving command line arguments inside a Qt application
    By prykHetQuo in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2009, 15:28
  4. passing arguments in SLOT
    By eleanor in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2008, 22:55
  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.