题
我正在尝试更改某个文本框消息。它将显示我的输出。
这就是我在main()
中的内容#include "form2.h"
....
string recvMSG = "random";
182 :: Form2 :: changeOutput(recvMSG); ...
在我的form2.h中我有:
#include <string.h>
#include <iostream>
#include <stdlib.h>
...
void Form2::changeOutput(string s)
{
QString s1 = i18n(s);
output_box.setText(s1);
}
但我仍然得到: .ui / form2.h:56:错误:<!>#8216; string <!>#8217;尚未宣布
感谢。
编辑:: kk所以现在显示:: TCPClient.cpp:182:错误:无法调用成员函数<!>#8216;虚拟void Form2 :: changeOutput(std :: string)<!>#8217;没有对象
解决方案
string
位于std
命名空间中,因此您需要将其称为std::string
,或者您需要使用using namespace std;
或using std::string;
在当前范围中使用该名称。
此标题也称为string.h
,而不是QString
,因此请以这种方式包含它:
#include <string>
一般情况下,如果您将QT组件与通常采用<=>参数的QT组件结合使用,您也可能希望使用QT的<=>代替<=>。
其他提示
我猜你应该使用标题<string>
然后使用std::string
(更好的是const std::string &
)
不隶属于 StackOverflow