• 12942阅读
  • 2回复

[提问]编译问题--> error: ‘Qstring’ was not declared in this scope [复制链接]

上一主题 下一主题
离线dragonfever
 
只看楼主 倒序阅读 楼主  发表于: 2011-04-16
今天编译用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: *** [slotform.o] 错误 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<qstring.h>,还在slotform.h中加入了类声明:class Qstring,但是仍是如上报错,不知道到底哪里出的问题,向各位大侠求教!!

离线wxj120bw

只看该作者 1楼 发表于: 2011-04-16
引用楼主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头文件
离线dragonfever
只看该作者 2楼 发表于: 2011-04-17
回 1楼(wxj120bw) 的帖子
多谢楼上关注,找到问题所在了,是细节错误,应该是QString,我原来在程序中写成了Qstring,改过来后,我只在slotform.h中加入了类声明class QString,不用加#include <qstring.h>,然后qmake,再make,编译成功,在qvfb中运行正确~
快速回复
限100 字节
 
上一个 下一个