Results 1 to 2 of 2

Thread: how to concatenate a variable with a string

  1. #1
    Join Date
    Jul 2010
    Posts
    18
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default how to concatenate a variable with a string

    hi i am trying to concatenate a variable with a string. How can i do this?
    here is the code
    Qt Code:
    1. void login::show_user()
    2. {
    3. QString user_name = user->text();
    4. QMessageBox::information(this, tr("Your Username"),
    5. tr("Your username is user_name"));
    6. }
    To copy to clipboard, switch view to plain text mode 

    i want to concatenate user_name in QMessageBox to display username

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to concatenate a variable with a string

    You can simply use + operator, or opt of string arguments..
    QString message = "Your user name is " + user_name;
    QString message = QString("Your user name is %1").arg(user_name).

    Do read Qt Assistant..it helps

Similar Threads

  1. concatenate two values
    By rk0747 in forum Qt Programming
    Replies: 4
    Last Post: 30th May 2010, 10:43
  2. Get value for variable name defined as string
    By webquinty in forum General Programming
    Replies: 2
    Last Post: 18th November 2009, 10:30
  3. Concatenate two array elements
    By b1 in forum General Programming
    Replies: 6
    Last Post: 29th October 2007, 20:43
  4. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  5. how to concatenate .wav files with different frequencies
    By BOMMACANTI in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2006, 13:51

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.