Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to concatenate strings+ int in messageBox qt c++?
Forum Updated to NodeBB v4.3 + New Features

How to concatenate strings+ int in messageBox qt c++?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
17 Posts 3 Posters 2.0k 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.
  • R Offline
    R Offline
    RuWex
    wrote on last edited by
    #8

    yes, but i just wanted to see if uts work well...
    anyway,
    do you have any idea what can i do??
    if I dont want to paste on the messageBox just what that standing on some condition?

    JonBJ 1 Reply Last reply
    0
    • R RuWex

      yes, but i just wanted to see if uts work well...
      anyway,
      do you have any idea what can i do??
      if I dont want to paste on the messageBox just what that standing on some condition?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #9

      @RuWex said in How to concatenate strings+ int in messageBox qt c++?:

      do you have any idea what can i do??

      No because as I said I have no idea what you are asking.

      if I dont want to paste on the messageBox just what that standing on some condition?

      Nor do I know what this means.

      I will leave you to see if anyone else answers.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RuWex
        wrote on last edited by
        #10

        @JonB said in How to concatenate strings+ int in messageBox qt c++?:

        Nor do I know what this means.
        I will leave you to see if anyone else answers.

        Sorry, I'll try to explain myself more clearly, I want to send a message to the user in the messageBox, but I don't want all the %X to be displayed, but only those that meet a certain condition. Does anyone have an idea how to do this?

        JonBJ 1 Reply Last reply
        0
        • R RuWex

          @JonB said in How to concatenate strings+ int in messageBox qt c++?:

          Nor do I know what this means.
          I will leave you to see if anyone else answers.

          Sorry, I'll try to explain myself more clearly, I want to send a message to the user in the messageBox, but I don't want all the %X to be displayed, but only those that meet a certain condition. Does anyone have an idea how to do this?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #11

          @RuWex
          Instead of your current

          QString text= QString("Estimated time to complete the test %1 days, %2 hours, %3 minutes, %4 seconds").arg(remainingDays).arg(remainingHours).arg(remainingMinute).arg(second);

          Instead of this fixed string with its %...s and matching arg()s, create a different string with arguments according to your if condition. Or build it up one bit at a time.

          Maybe you have in mind something like this:

          QString text= QString("Estimated time to complete the test: ");
          if (remainingDays > 0)
            text.append(QString("%1 days, ").arg(remainingDays));
          if (remainingHours > 0)
            text.append(QString("%1 hours, ").arg(remainingHours));
          // and so on
          
          Christian EhrlicherC 1 Reply Last reply
          4
          • R Offline
            R Offline
            RuWex
            wrote on last edited by
            #12

            ou!
            Thanks, this is exactly what I wanted!!

            1 Reply Last reply
            0
            • JonBJ JonB

              @RuWex
              Instead of your current

              QString text= QString("Estimated time to complete the test %1 days, %2 hours, %3 minutes, %4 seconds").arg(remainingDays).arg(remainingHours).arg(remainingMinute).arg(second);

              Instead of this fixed string with its %...s and matching arg()s, create a different string with arguments according to your if condition. Or build it up one bit at a time.

              Maybe you have in mind something like this:

              QString text= QString("Estimated time to complete the test: ");
              if (remainingDays > 0)
                text.append(QString("%1 days, ").arg(remainingDays));
              if (remainingHours > 0)
                text.append(QString("%1 hours, ").arg(remainingHours));
              // and so on
              
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #13

              @JonB said in How to concatenate strings+ int in messageBox qt c++?:

              QString text= QString("Estimated time to complete the test: ");

              QString text= tr("Estimated time to complete the test: %n day(s)").arg(remainingDays);

              ;)

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

              JonBJ 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @JonB said in How to concatenate strings+ int in messageBox qt c++?:

                QString text= QString("Estimated time to complete the test: ");

                QString text= tr("Estimated time to complete the test: %n day(s)").arg(remainingDays);

                ;)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #14

                @Christian-Ehrlicher
                I don't follow?! I don't think you're pointing out the tr(), I don't know what your %n is about, and OP wants the Estimated time .... at the start unconditionally....
                I think you're trying a piece of humor that is too droll/subtle for me to grasp?

                Christian EhrlicherC 1 Reply Last reply
                0
                • JonBJ JonB

                  @Christian-Ehrlicher
                  I don't follow?! I don't think you're pointing out the tr(), I don't know what your %n is about, and OP wants the Estimated time .... at the start unconditionally....
                  I think you're trying a piece of humor that is too droll/subtle for me to grasp?

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

                  @JonB said in How to concatenate strings+ int in messageBox qt c++?:

                  I think you're trying a piece of humor that is too droll/subtle for me to grasp?

                  No, it's the correct way to translate a string for singular/plural - we discuessed this some days ago already.
                  See https://doc.qt.io/qt-6/i18n-source-translation.html#handling-plurals

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

                  JonBJ 1 Reply Last reply
                  3
                  • Christian EhrlicherC Christian Ehrlicher

                    @JonB said in How to concatenate strings+ int in messageBox qt c++?:

                    I think you're trying a piece of humor that is too droll/subtle for me to grasp?

                    No, it's the correct way to translate a string for singular/plural - we discuessed this some days ago already.
                    See https://doc.qt.io/qt-6/i18n-source-translation.html#handling-plurals

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #16

                    @Christian-Ehrlicher
                    Ohhhhhhhh.... Well I'm certainly not writing this for Polish/Russian!
                    My look up of QString::arg() did not show any %n?
                    And if we are going to be that fussy, will %n day(s) come out as 1 day [sic.] if n == 1??

                    Oh I see, it's in that link.

                    OK, @Christian-Ehrlicher, how about this then: I want the count in the message to be on sheep. yes, that's right, how many sheep something takes. How do I do that cross-language then?

                    %n sheep(s) --- wrong for English in plural
                    %n sheep --- wrong for French etc. in plural
                    

                    ? ;-)

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Christian-Ehrlicher
                      Ohhhhhhhh.... Well I'm certainly not writing this for Polish/Russian!
                      My look up of QString::arg() did not show any %n?
                      And if we are going to be that fussy, will %n day(s) come out as 1 day [sic.] if n == 1??

                      Oh I see, it's in that link.

                      OK, @Christian-Ehrlicher, how about this then: I want the count in the message to be on sheep. yes, that's right, how many sheep something takes. How do I do that cross-language then?

                      %n sheep(s) --- wrong for English in plural
                      %n sheep --- wrong for French etc. in plural
                      

                      ? ;-)

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

                      @JonB said in How to concatenate strings+ int in messageBox qt c++?:

                      %n sheep(s) --- wrong for English in plural
                      %n sheep --- wrong for French etc. in plural

                      ? ;-)

                      You have to enter two translations in linugist then (or more for other languages). But there is only one tr() call in your code.

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

                      1 Reply Last reply
                      0

                      • Login

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