C++ 字符串尚未声明,QT
我正在尝试更改某个文本框消息。它将显示我的输出 这是我的主要内容() 182::Form2::changeOutput(recvMSG); 在我的表格2.h中,我有:C++ 字符串尚未声明,QT,c++,qt,C++,Qt,我正在尝试更改某个文本框消息。它将显示我的输出 这是我的主要内容() 182::Form2::changeOutput(recvMSG); 在我的表格2.h中,我有: #include <string.h> #include <iostream> #include <stdlib.h> ... void Form2::changeOutput(string s) { QString s1 = i18n(s);
#include <string.h>
#include <iostream>
#include <stdlib.h>
...
void Form2::changeOutput(string s)
{
QString s1 = i18n(s);
output_box.setText(s1);
}
#包括
#包括
#包括
...
void Form2::changeOutput(字符串s)
{
QString s1=i18n(s);
输出_box.setText(s1);
}
但我仍然得到:
.ui/form2.h:56:错误:“字符串”尚未声明
谢谢
编辑::kk现在显示::
TCPClient.cpp:182:错误:无法调用没有对象的成员函数“virtual void Form2::changeOutput(std::string)”
string
位于std
命名空间中,因此您需要将其称为std::string
,或者,您需要使用名称空间std使名称在当前范围内可用代码>或使用std::string代码>
另外,标题名为string
,而不是string.h
,因此应以这种方式包含它:
#include <string>
#包括
通常,如果您将QT的QString
与通常采用QString
参数的QT组件结合使用,您可能还希望使用QT的QString
而不是std::string
。我想您应该使用标题
,然后使用std::string
(更好的方法是const std::string&
)更好的方法是不要混合使用STL和Qt字符串类和容器。确实如此,但有时您希望隐藏在类接口中使用的库的内部数据类型,以避免客户端必须包含第三方头。这都是间接的。
#include <string>