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. Concatenate string to QString
QtWS25 Last Chance

Concatenate string to QString

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 23.5k Views
  • 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.
  • D Offline
    D Offline
    david_aa
    wrote on last edited by
    #1

    Hi all,

    I need to concatenate the start date, start time with the end date, end time.

    For example: 2011/05/18 10:53:55.371;2012/09/22 10:57:32.168

    Can you help me?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Search "concat" in the "QString documentation":http://qt-project.org/doc/qt-5/qstring.html

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • D Offline
        D Offline
        david_aa
        wrote on last edited by
        #3

        Hi,

        I did this:

        // Retrieves, appends the Start Date and Start Time and converts it to standard
        CSPTDateTime objDateInitial;
        dateInitial += " " + hourInitial;
        objDateInitial.SetYMD(dateInitial, 2);

        //Retrieves, appends the End Date and End Time and converts it to standard
        CSPTDateTime objDateFinal;
        dateFinal += " " + hourFinal;
        objDateFinal.SetYMD(dateFinal, 2);

        I need to concatenate the variable QString m_LinhaComando at: dateInitial string, string hourInitial and dateEnd, HourEnd

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Sorry, I don't understand your question.

          You already know how to concatenate dateInitial with hourInitial (and you concatenated dateFinal with hourfFinal). What's the problem?

          EDIT: Do you want to concatenate a std::string with a QString? Convert your std::string to a QString first. See the QString documentation for details.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • D Offline
            D Offline
            david_aa
            wrote on last edited by
            #5

            Hi,

            Yes, I am concatenating the start date and start time as follows:

            dateInitial += " " + hourInitial;
            dateFinal += " " + hourFinal;

            But, I need to concatenate in one variable so that it looks like for example:

            Example:
            m_LinhaComando = dateInitial += " " + hourInitial;dateFinal += " " + hourFinal;

            Example:
            m_LinhaComando = 2011/05/18 10:53:55.371;2012/09/22 10:57:32.168

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Use + instead of +=.

              += is the combination of concatenation and assignment.

              The 2 pieces of code below both do the same thing. (This is basic C++)
              @
              // Technique #1:
              dateInitial += " " + hourInitial;
              @
              @
              // Technique #2:
              dateInitial = dateInitial + " " + hourInitial;
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • D Offline
                D Offline
                david_aa
                wrote on last edited by
                #7

                But this error occurs in this line:

                QString m_LinhaComando;

                Line: m_LinhaComando = dateInitial + " " + hourInitial;
                Error: error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  Like I said before, you need to convert dateInitial and hourInitial to QString first. See the "QString documentation":http://qt-project.org/doc/qt-5/qstring.html on how to convert std::string to QString.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TT_NBE
                    wrote on last edited by
                    #9

                    First make sure all parts are QString:

                    for numbers this is
                    QString nr = QString::number(15);

                    for other types see the many constructors / static methods in QString.

                    Than use the "append" function of QString.

                    But I know if your used to java or c# this is a pain in the ...

                    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