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. strcat c++ ERROR
Forum Updated to NodeBB v4.3 + New Features

strcat c++ ERROR

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 715 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
    #1
    class y{
       public:
              void func(QString )
              
       private:
             QString w;
    }
    void y:: func(QString x)
    { 
           strcat(w,x)
    }
              
    

    but I have an error:
    no matching function for call 'strcat'
    do you understand my problem?
    thank:)

    jsulmJ 1 Reply Last reply
    0
    • R RuWex
      class y{
         public:
                void func(QString )
                
         private:
               QString w;
      }
      void y:: func(QString x)
      { 
             strcat(w,x)
      }
                
      

      but I have an error:
      no matching function for call 'strcat'
      do you understand my problem?
      thank:)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @RuWex strcat has no idea what QString is. Please take a closer look at what parameters strcat takes...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      1
      • jsulmJ jsulm

        @RuWex strcat has no idea what QString is. Please take a closer look at what parameters strcat takes...

        R Offline
        R Offline
        RuWex
        wrote on last edited by
        #3

        @jsulm char *....:(
        how can I convert QString to char *?

        JonBJ jsulmJ KroMignonK 3 Replies Last reply
        0
        • R RuWex

          @jsulm char *....:(
          how can I convert QString to char *?

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

          @RuWex
          Why would you want to? I strongly suspect you do want or need to call strcat() in any form, so why pursue that? You can append to QStrings: QString &QString::append(const QString &str). If you try to turn it into a char * to use with strcat(), my guess is you have not understood that you would not have the storage area you would need to strcat() onto it.

          1 Reply Last reply
          2
          • R RuWex

            @jsulm char *....:(
            how can I convert QString to char *?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @RuWex It's all in the documentation.
            Depending on used encoding you can use https://doc.qt.io/qt-6/qstring.html#toLatin1 for example.

            But why do you need strcat to concatenate two QStrings?!

            https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              @jsulm @JonB
              I need if for example I get in x="world"
              and in W I have W= "hello"
              I want to get W="hello world"
              can I instead do W+=x?

              jsulmJ JonBJ 2 Replies Last reply
              0
              • R RuWex

                @jsulm @JonB
                I need if for example I get in x="world"
                and in W I have W= "hello"
                I want to get W="hello world"
                can I instead do W+=x?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @RuWex Again: the answer is in the documentation which you really should use.

                QString &	operator+=(const QString &other)
                QString &	operator+=(QChar ch)
                QString &	operator+=(QStringView str)
                QString &	operator+=(QLatin1StringView str)
                QString &	operator+=(const char *str)
                QString &	operator+=(const QByteArray &ba)
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • R RuWex

                  @jsulm @JonB
                  I need if for example I get in x="world"
                  and in W I have W= "hello"
                  I want to get W="hello world"
                  can I instead do W+=x?

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

                  @RuWex
                  Trust us, you don't want to use strcat()! :) Nor any of those C string functions like strcpy() etc., the C++/Qt world has moved on since then.

                  Start learning to use QString and its operators, much easier and safer.

                  1 Reply Last reply
                  0
                  • R RuWex

                    @jsulm char *....:(
                    how can I convert QString to char *?

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by KroMignon
                    #9

                    @RuWex said in strcat c++ ERROR:

                    how can I convert QString to char *?

                    Please don't use try to program in C++ as you would do it with a C compiler!
                    This is a nonsense!

                    QString is a C++ class which includes all you need for string manipulation. All memory allocation will be handled internally by QString, even to string type (unicode, UTF-8, etc.) is taken in account.

                    If you use strcat(), you will have to take care about memory allocation/deallocation yourself. This will be error-prone and much more complex to code.

                    Why do you want doing this, when you are working is QString???

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    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