• 8523阅读
  • 5回复

在编译中提示变量未定义 [复制链接]

上一主题 下一主题
离线ghoulr
 

只看楼主 正序阅读 楼主  发表于: 2006-04-08
我是刚刚才开始学习Qt(也是刚接触linux),按照教程中的helloworld作的第一个程序就不能编译...
出错提示是这样的:
main.cpp: In function `int main(int, char**)':
main.cpp:10: `hellobtn' undeclared (first use this function)
main.cpp:10: (Each undeclared identifier is reported only once for each
  function it appears in.)
main.cpp:11: `show' undeclared (first use this function)
main.cpp:12: `exec' undeclared (first use this function)
make: *** [.obj/main.o] Error 1


这是我的源程序:
#include <qapplication.h>
#include <qpushbutton.h>

int main(int argc,char **argv)
{
  QApplication a(argc,argv);
 
  QPushButton Hellobtn("Hello World",0);
  Hellobtn.resize(100,20);
  a.setMainWidget(*hellobtn);
  Hellobtn,show();
  return a,exec();
}
请问问题是出在哪里,谢谢
离线bjtony

只看该作者 5楼 发表于: 2006-04-09
这不是关键,我感觉QT 3比较适合你。但是学好C++是基础。
有条件不要在虚拟机上。
离线ghoulr

只看该作者 4楼 发表于: 2006-04-08
嗯,我把那句注释掉以后编译成功了,谢谢

顺便问一下,初学是不是不适合从4.x版本开始啊
[ 此贴被ghoulr在2006-04-08 14:06重新编辑 ]
离线XChinux

只看该作者 3楼 发表于: 2006-04-08
你用的是Qt 4.1.0,在Qt4.x里,已经没有了setMainWidget()这个函数了。
你把它去掉 就行了。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线ghoulr

只看该作者 2楼 发表于: 2006-04-08
。。。是我自己编程的时候不小心,再加上虚拟机显示比较模糊,我把程序改成这样以后:
#include <qapplication.h>
#include <qpushbutton.h>

int main(int argc,char **argv)
{
  QApplication a(argc,argv);
 
  QPushButton Hellobtn("Hello World",0);
  Hellobtn.resize(100,20);
  a.setMainWidget(&Hellobtn);
  Hellobtn.show();
  return a.exec();
}

出现的提示改为了:
main.cpp: In function `int main(int, char**)':
main.cpp:10: no matching function for call to `QApplication::setMainWidget(
  QPushButton*)'
make: *** [.obj/main.o] Error 1

但是把 a.setMainWidget(&Hellobtn);改成 a.setMainWidget(*Hellobtn);后还是不能编译,出来的提示变成了:


main.cpp: In function `int main(int, char**)':
main.cpp:10: no match for `* QPushButton&' operator
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qpoint.h:137: candidates are:
  const QPoint operator*(const QPoint&, double)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qpoint.h:140:
  const QPoint operator*(double, const QPoint&)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qpoint.h:305:
  const QPointF operator*(double, const QPointF&)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qpoint.h:300:
  const QPointF operator*(const QPointF&, double)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qsize.h:145:           const
  QSize operator*(const QSize&, double)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qsize.h:148:           const
  QSize operator*(double, const QSize&)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qsize.h:301:           const
  QSizeF operator*(const QSizeF&, double)
/usr/local/Trolltech/Qt-4.1.0/include/QtCore/qsize.h:304:           const
  QSizeF operator*(double, const QSizeF&)
make: *** [.obj/main.o] Error 1

麻烦再帮我看看,谢谢
[ 此贴被ghoulr在2006-04-08 13:28重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2006-04-08
a.setMainWidget(*hellobtn);
应该改为a.setMainWidget(&Hellobtn);
还有下面的逗号改为分号
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个