I try to add two QStrings into one. I've read a lot about:
我尝试将两个qstring添加到一个中。我读过很多关于:
QString NAME = QString + QString
QString NAME = QString + QString
but this doesn't helps me here. Thats how my code look so far:
但这对我没有帮助。到目前为止,我的代码是这样的:
test.h
test.h
#ifndef TEST_H
#define TEST_H
#include <QString>
#include <QFile>
#include <QDir>
class Test
{
public:
void createProject(QString* p, QString*n);
};
#endif // TEST_H
test.cpp
test.cpp
#include "test.h"
#include <QFile>
#include <QString>
#include <QDir>
void Test::createProject(QString *p, QString *n)
{
QString result = p + n;
QDir dir(result);
if (dir.exists())
{
// ok
}
else
{
printf("Error!\n");
}
}
(ignore the code about checking if the directory exists, btw I use Qt 4.8.6)
(忽略检查目录是否存在的代码,顺便说一句,我使用Qt 4.8.6)
So now when I try to compile, I get this error:
所以当我尝试编译时,我得到了这个错误:
test.cpp: In member function 'void Test::createProject(QString*, QString*)': test.cpp:8:21: error: invalid operands of types 'QString*' and 'QString*' to binary 'operator+'
QString result = p + n;测试。cpp:在成员函数‘void Test::createProject(QString*, QString*)’中:Test。错误:将‘QString*’和‘QString*’类型的操作数无效到‘operator+’QString result = p + n;
How can I make this work? Also using += instead of + doesn't works here.
我怎样才能让它工作呢?用+=代替+在这里也不行。
~ Jan
~ 1月
1 个解决方案
#1
3
Indeed you are adding their address as p
and n
are pointer. try adding their value as:
实际上,你添加了他们的地址作为p和n是指针。试着把它们的价值增加为:
QString result = *p + *n;
#1
3
Indeed you are adding their address as p
and n
are pointer. try adding their value as:
实际上,你添加了他们的地址作为p和n是指针。试着把它们的价值增加为:
QString result = *p + *n;