Results 1 to 4 of 4

Thread: What data type is the text in addAction(tr("&First Item"))

  1. #1
    Join Date
    Apr 2017
    Posts
    43
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: What data type is the text in addAction(tr("&First Item"))

    This code comes from the grouppushbuttonbox example at
    http://doc.qt.io/qt-5/qtwidgets-widg...x-example.html

    At run time I want to build a string to replace the ("&First Item") with a concatenated integer. It fails to compile saying that std::string is in valid for the argument. QString fails for the same reason.
    There has to be a way of changing this text at startup. Any help would be appreciated.

    Thank You

    emp1953


    Added after 25 minutes:


    Here is the compiler error

    /home/123/groupbox_example/window.cpp:102: error: no matching function for call to 'Window::tr(std::string&)'
    menu->addAction(tr(str));
    ^
    Last edited by emp1953; 24th March 2018 at 22:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    425
    Thanked 57 Times in 53 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What data type is the text in addAction(tr("&First Item"))

    QObject::tr() takes a const char* as first argument: http://doc.qt.io/qt-5/qobject.html#tr

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,975
    Thanks
    232
    Thanked 627 Times in 617 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: What data type is the text in addAction(tr("&First Item"))

    So this would work:

    Qt Code:
    1. menu->addAction( tr( str.c_str() ) );
    To copy to clipboard, switch view to plain text mode 

    When you get a "no matching function call" compiler error it almost always means you have 1) spelled the name of the function incorrectly, 2) are trying to call the function with the wrong type of argument, or 3) are calling it with the wrong number of arguments.

    The Qt documentation is always your friend.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    emp1953 (30th April 2019)

  5. #4
    Join Date
    Apr 2017
    Posts
    43
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: What data type is the text in addAction(tr("&First Item"))

    Quote Originally Posted by d_stranz View Post
    So this would work:

    Qt Code:
    1. menu->addAction( tr( str.c_str() ) );
    To copy to clipboard, switch view to plain text mode 

    When you get a "no matching function call" compiler error it almost always means you have 1) spelled the name of the function incorrectly, 2) are trying to call the function with the wrong type of argument, or 3) are calling it with the wrong number of arguments.

    The Qt documentation is always your friend.
    Thank you d_stranz, it did work.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 19:21
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 4
    Last Post: 5th March 2010, 18:03
  4. Replies: 3
    Last Post: 25th August 2009, 13:03
  5. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 11:45

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.