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
    55
    Thanks
    8
    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 23:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 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
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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
    55
    Thanks
    8
    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, 20:21
  2. Replies: 1
    Last Post: 7th April 2010, 22:46
  3. Replies: 4
    Last Post: 5th March 2010, 19:03
  4. Replies: 3
    Last Post: 25th August 2009, 14: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, 12: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.