Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does it show me this warning?
Forum Updated to NodeBB v4.3 + New Features

Why does it show me this warning?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 266 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • lincolnL Online
    lincolnL Online
    lincoln
    wrote on last edited by lincoln
    #1

    Hi guys, I have the following code:

    In My .hpp

    void setLabelInfo(const QString &color, const QString& userName="PUBLIC") noexcept;
    

    The .cpp

    void Widget::setLabelInfo(const QString& color, const QString& userName) noexcept
    {
      ui->lblInfo->setText(QString("<span style='color:%1;'>"
                                   "<strong>MyCompany - Super User "
                                   "</strong></span>").arg(color));
    
    
      ui->lblState->setText(QString("<span style='color:%1;'>"
                                    "<strong>User: %2"
                                    "</strong></span>").arg(color).arg(userName));
    
    }
    
    

    I get this warning, here I leave the image, why does that message appear, and how can I improve it, thanks in advance.

    83f05416-bf9b-4188-b215-39565b5df500-image.png

    I am using Qt 6.2.4 and Clang compiler 16.0.5

    Solitary wolf

    Christian EhrlicherC 1 Reply Last reply
    0
    • lincolnL lincoln

      Hi guys, I have the following code:

      In My .hpp

      void setLabelInfo(const QString &color, const QString& userName="PUBLIC") noexcept;
      

      The .cpp

      void Widget::setLabelInfo(const QString& color, const QString& userName) noexcept
      {
        ui->lblInfo->setText(QString("<span style='color:%1;'>"
                                     "<strong>MyCompany - Super User "
                                     "</strong></span>").arg(color));
      
      
        ui->lblState->setText(QString("<span style='color:%1;'>"
                                      "<strong>User: %2"
                                      "</strong></span>").arg(color).arg(userName));
      
      }
      
      

      I get this warning, here I leave the image, why does that message appear, and how can I improve it, thanks in advance.

      83f05416-bf9b-4188-b215-39565b5df500-image.png

      I am using Qt 6.2.4 and Clang compiler 16.0.5

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @lincoln said in Why does it show me this warning?:

      I get this warning,

      Which warning?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      lincolnL 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @lincoln said in Why does it show me this warning?:

        I get this warning,

        Which warning?

        lincolnL Online
        lincolnL Online
        lincoln
        wrote on last edited by
        #3

        @Christian-Ehrlicher that warning

        Solitary wolf

        J.HilkJ 1 Reply Last reply
        0
        • lincolnL lincoln

          @Christian-Ehrlicher that warning

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Lincoln you're supposed to use this arg overload

          https://doc.qt.io/qt-6/qstring.html#arg-14

          which is one call, currently you're calling arg(arg) and on the temporary you call again arg(arg) with the 2nd argument

          ui->lblState->setText(QString("<span style='color:%1;'>"
          "<strong>User: %2"
          "</strong></span>").arg(color, userName));

          Assuming color and userName are QStrings or implicitly converted. Also use QStringLiteral here instead of QString, its "cleaner"


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved