strcat c++ ERROR
-
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:) -
@RuWex strcat has no idea what QString is. Please take a closer look at what parameters strcat takes...
-
@RuWex
Why would you want to? I strongly suspect you do want or need to callstrcat()
in any form, so why pursue that? You can append toQString
s: QString &QString::append(const QString &str). If you try to turn it into achar *
to use withstrcat()
, my guess is you have not understood that you would not have the storage area you would need tostrcat()
onto it. -
@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?!
-
@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)
-
-
@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 byQString
, 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
???