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 717 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 15 Nov 2022, 11:25 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:)

    J 1 Reply Last reply 15 Nov 2022, 11:53
    0
    • R RuWex
      15 Nov 2022, 11:25
      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:)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 15 Nov 2022, 11:53 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 15 Nov 2022, 11:58
      1
      • J jsulm
        15 Nov 2022, 11:53

        @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 15 Nov 2022, 11:58 last edited by
        #3

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

        J J K 3 Replies Last reply 15 Nov 2022, 12:01
        0
        • R RuWex
          15 Nov 2022, 11:58

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

          J Online
          J Online
          JonB
          wrote on 15 Nov 2022, 12:01 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
            15 Nov 2022, 11:58

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 15 Nov 2022, 12:01 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 15 Nov 2022, 12:04 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?

              J J 2 Replies Last reply 15 Nov 2022, 12:05
              0
              • R RuWex
                15 Nov 2022, 12:04

                @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?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 15 Nov 2022, 12:05 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
                  15 Nov 2022, 12:04

                  @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?

                  J Online
                  J Online
                  JonB
                  wrote on 15 Nov 2022, 12:08 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
                    15 Nov 2022, 11:58

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

                    K Offline
                    K Offline
                    KroMignon
                    wrote on 15 Nov 2022, 22:54 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

                    1/9

                    15 Nov 2022, 11:25

                    • Login

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