首页| 论坛| 消息

标题:【提问】make出错
作者:gaoyu
日期:2005-12-24 13:42
内容:

下面是我的源程序(HelloWorld.cpp):
#include "HelloWorld.h"
int main(int argc,char **argv)
{
QApplication a(argc,argv);

QWidget mainwindow;
mainwindow.setMinimumSize(200,100);
mainwindow.setMaximumSize(200,100);

QPushButton helloworld("Hello World!",&mainwindow);
helloworld.setGeometry(&mainwindow);
mainwindow.show();
return a.exec();
}
/*HelloWorld.h*/
#include
#include
#include
写了一个工程文件HelloWorld.pro:
CONFIG += qt
HEADERS += HelloWorld.h
SOURCES += HelloWorld.cpp

利用qmake工具生成Makefile,命令如下:
qmake -o Makefile HelloWorld.pro

但之后运行make的时候,出现如下错误:
# make
g++ -c -pipe -g -D_REENTRANT -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.1.0/include/QtCore -I/usr/local/Trolltech/Qt-4.1.0/include/QtGui -I/usr/local/Trolltech/Qt-4.1.0/include -I. -I. -o HelloWorld.o HelloWorld.cpp
In file included from HelloWorld.cpp:1:
HelloWorld.h:3:25: warning: no newline at end of file
HelloWorld.cpp: In function `int main(int, char**)':
HelloWorld.cpp:12: no matching function for call to `QPushButton::setGeometry(
QWidget*)'
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qwidget.h:848: candidates are: void
QWidget::setGeometry(int, int, int, int)
/usr/local/Trolltech/Qt-4.1.0/include/QtGui/qwidget.h:419: void
QWidget::setGeometry(const QRect&)
make: *** Error 1

请问各位大侠,是怎么回事啊?
谢谢!


#1 [gaoyu 12-24 13:52]
sorry,刚才发现把程序抄错了.应该改成
#include "HelloWorld.h"
int main(int argc,char **argv)
{
QApplication a(argc,argv);

QWidget mainwindow;
mainwindow.setMinimumSize(200,100);
mainwindow.setMaximumSize(200,100);

QPushButton helloworld("Hello World!",&mainwindow);
helloworld.setGeometry(20,20,160,60);

//a.setMainWidget(&mainwindow);
mainwindow.show();
return a.exec();
}
有请大侠,如果我要加上去掉的那一行,就会出现错误,如下所示
# make
g++ -c -pipe -g -D_REENTRANT -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.1.0/include/QtCore -I/usr/local/Trolltech/Qt-4.1.0/include/QtGui -I/usr/local/Trolltech/Qt-4.1.0/include -I. -I. -o HelloWorld.o HelloWorld.cpp
In file included from HelloWorld.cpp:1:
HelloWorld.h:3:25: warning: no newline at end of file
HelloWorld.cpp: In function `int main(int, char**)':
HelloWorld.cpp:14: no matching function for call to `QApplication::
setMainWidget(QWidget*)'
make: *** Error 1
谢谢!
文字
#2 [fanyu 12-24 13:54]
a.setMainWidget(&mainwindow);
这是qt 3.X支持的成员函数,qt 4已不在支持了。
#3 [gaoyu 12-24 13:58]
谢谢,那请问qt4怎么想实现相同的功能呢?
#4 [gaoyu 12-24 14:00]
请问版主,我现在装的是qt4.1.0,能不能再把qt3.x装上,会不会冲突?应该怎么装呢?
谢谢!
#5 [XChinux 12-24 14:46]
下面是引用gaoyu于2005-12-24 14:00发表的:
请问版主,我现在装的是qt4.1.0,能不能再把qt3.x装上,会不会冲突?应该怎么装呢?
谢谢!
关键是正确的程序和正确的QTDIR环境变量设置。
这些都是使用编译器的常识。

回复 发表
主题 版块