Results 1 to 6 of 6

Thread: how to use arguments in Qt?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: how to use arguments in Qt?

    For example, add a second parameter in VerticalBox constructor:
    Qt Code:
    1. VerticalBox( const QString& fileName = QString(), QWidget * parent = NULL )
    To copy to clipboard, switch view to plain text mode 
    And use it to setup lineEdit in constructor:
    Qt Code:
    1. VerticalBox::VerticalBox(const QString& fileName,QWidget *parent) : QWidget(parent)
    2. {
    3. QVBoxLayout *vbox = new QVBoxLayout(this);
    4. QHBoxLayout *contentBox = new QHBoxLayout();
    5. QHBoxLayout *buttonBox = new QHBoxLayout();
    6.  
    7. //HBox contentBox containing the QLabel and QLineEdit:
    8. QLabel *name = new QLabel("Name: ", this);
    9. QLineEdit *name_in = new QLineEdit(this);
    10. name_in->setText(fileName);
    11. contentBox->addWidget(name);
    12. contentBox->addWidget(name_in);
    13. ...
    To copy to clipboard, switch view to plain text mode 

    In order to pass the "fileName" argument you can use argv array:
    Qt Code:
    1. ...
    2. QApplication app(argc, argv);
    3. const QString toPass = argc > 1 ? QString(argv[1]) : QString();
    4. VerticalBox window( toPass );
    To copy to clipboard, switch view to plain text mode 
    argv[0] is usually name of the program, argv[1], argv[2], ... are parameters passed.

    You can also use QCoreApplication::arguments()
    Last edited by stampede; 23rd January 2011 at 15:11.

  2. The following user says thank you to stampede for this useful post:

    mr_kazoodle (23rd January 2011)

Similar Threads

  1. QProcess Arguments
    By doggrant in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2010, 16:45
  2. qmake conditionals/arguments
    By tbscope in forum Qt Tools
    Replies: 2
    Last Post: 10th August 2010, 07:21
  3. Using Qlibrary on a function that uses arguments
    By schall_l in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2008, 21:58
  4. QVector arguments
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2007, 10:47
  5. Signal arguments limit to ?
    By ucntcme in forum Qt Programming
    Replies: 5
    Last Post: 1st March 2006, 17:37

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.