首页| 论坛| 消息

标题:编译问题--> error: ‘Qstring’ was not declared in this scope
作者:dragonfever
日期:2011-04-16 21:15
内容:

今天编译用qt3的designer设计一个简单的加法器程序,make时,报错如下:
......
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -O2-DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/root/qt/qt_pc/qt-embedded-free-3.3.8/mkspecs/default -I. -I. -I/root/qt/qt_pc/qt-embedded-free-3.3.8/include -o slotform.o slotform.cpp
In file included from slotform.cpp:22:
slotform.ui.h: In member function ‘virtual void slotform::add()’:
slotform.ui.h:16: error: ‘Qstring’ was not declared in this scope
slotform.ui.h:16: error: expected ‘;’ before ‘str1’
slotform.ui.h:19: error: ‘str1’ was not declared in this scope
slotform.ui.h:20: error: ‘str2’ was not declared in this scope
slotform.ui.h:28: error: ‘strResult’ was not declared in this scope
make: *** 错误 1
我的slotform.ui.h函数如下(它只是对槽函数add()的定义):

void slotform::add()
{
Qstring str1,str2,strResult;
double add1=0.0,add2=0.0,result=0.0;

str1=lineEdit1->text();
str2=lineEdit2->text();
bool ok1=FALSE,ok2=FALSE;
add1=str1.toDouble(&ok1);
add2=str2.toDouble(&ok2);

if(ok1&&ok2)
{
result=add1+add2;
strResult.sprintf("%f",result);
textLableResult->setText(strResult);
}
}
后来,我在slotform.h和slotform.cpp中都加入了#include,还在slotform.h中加入了类声明:class Qstring,但是仍是如上报错,不知道到底哪里出的问题,向各位大侠求教!!


#1 [wxj120bw 04-16 23:48]
引用楼主dragonfever于2011-04-16 21:15发表的 编译问题--> error: ‘Qstring’ was not declared in this scope :
今天编译用qt3的designer设计一个简单的加法器程序,make时,报错如下:
......
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -O2  -DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/root/qt/qt_pc/qt-embedded-free-3.3.8/mkspecs/default -I. -I. -I/root/qt/qt_pc/qt-embedded-free-3.3.8/include -o slotform.o slotform.cpp
In file included from slotform.cpp:22:
slotform.ui.h: In member function ‘virtual void slotform::add()’:
.......
你以前编译有过这样的错误提示 或者你的include有没有qstring.h头文件
#2 回 1楼(wxj120bw) 的帖子 [dragonfever 04-17 09:59]
多谢楼上关注,找到问题所在了,是细节错误,应该是QString,我原来在程序中写成了Qstring,改过来后,我只在slotform.h中加入了类声明class QString,不用加#include ,然后qmake,再make,编译成功,在qvfb中运行正确~

回复 发表
主题 版块