LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2007|回复: 16

qt

[复制链接]
发表于 2003-8-15 09:00:49 | 显示全部楼层 |阅读模式
我 在linux下按照qt教程做的hello.cpp

#include <qapplication.h>

#include <qpushbutton.h>



int main( int argc, char **argv )

{
    QApplication a( argc, argv );

   
QPushButton hello( "Hello world!", 0 );
   
hello.resize( 100, 30 );

   
a.setMainWidget( &hello );
   
hello.show();
   
return a.exec();

}

[root@locahost qt]# vim hello.cpp

[root@locahost qt]# qmake -project

[root@locahost qt]# qmake

[root@locahost qt]#make

g++ -c -pipe -Wall -W -I/usr/include/freetype2 -O2 -march=i386 -mcpu=i686 -fno-exceptions -DQT_NO_DEBUG  -I/usr/lib/qt3-gcc2.96/include -I/usr/lib/qt3-gcc2.96/mkspecs/default -o hello.o hello.cpp
g++  -o qt hello.o   -L/usr/X11R6/lib -lXext -lX11 -lm
hello.o: In function `main':
hello.o(.text+0x21): undefined reference to `QApplication:Application(int &, char **)'
hello.o(.text+0x2e): undefined reference to `QString:String(char const *)'
hello.o(.text+0x42): undefined reference to `QPushButton:PushButton(QString const &, QWidget *, char const *)'
hello.o(.text+0x5a): undefined reference to `QString::shared_null'
hello.o(.text+0x64): undefined reference to `QString::shared_null'
hello.o(.text+0x6d): undefined reference to `QStringData::deleteSelf(void)'
hello.o(.text+0x83): undefined reference to `QPushButton::resize(int, int)'
hello.o(.text+0x8f): undefined reference to `QApplication::setMainWidget(QWidget *)'
hello.o(.text+0x97): undefined reference to `QWidget::show(void)'
hello.o(.text+0x9f): undefined reference to `QApplication::exec(void)'
hello.o(.text+0xac): undefined reference to `QPushButton::~QPushButton(void)'
hello.o(.text+0xb6): undefined reference to `QApplication::~QApplication(void)'
collect2: ld returned 1 exit status
make: *** [qt] Error 1
不知道什么地方不对 有 一个错误??????
我的计算机里装有kdevelop的
发表于 2003-8-15 11:27:54 | 显示全部楼层
把你的pro文件贴出来
估计有些问题
建议加上
CONFIG += qt warn_on debug
然后qmake,make
你的错误应该是没有链接qt库
发表于 2003-8-15 16:53:50 | 显示全部楼层
看看你的环境变量设置是否正确。QTDIR和PATH是如何设置的。
 楼主| 发表于 2003-8-15 16:58:48 | 显示全部楼层

qt

我没有设置QTDIR 和PATH
要怎么设置的
我的程序在/root/ex1/ch1下面
发表于 2003-8-15 17:07:32 | 显示全部楼层
在/etc/profile中加入:
export QTDIR=你的QT安装目录
export PATH=$PATHQTDIR/bin

注意QT安装目录不是你写的QT程序所在目录。我看你对这个概念不清楚,特意提示一下。
 楼主| 发表于 2003-8-15 17:19:39 | 显示全部楼层

qt

是不是如果我的qt安装在/usr/local/下就在/etc/profile中写
export QTDIR=/usr/local
export PATH=$PATH:/usr/local/bin
其实我有个问题一直不太清楚
常常说PATH变量指的是什么
在windows下做java也要改PATH
不然要到/jdk1.3/bin下面做程序
这是什么原因
那么如果做perl程序是不是也要改的
做c程序怎么就不要改的??
发表于 2003-8-15 23:35:07 | 显示全部楼层
PATH就是查找程序的路径。当你在命令行上输入一行指令时,shell会根据PATH中指定的路径查找命令(或文件),如果找不到,则会报告错误。很多人在编译C程序后,象在dos下简单地输入a.out,结果不能执行,其实就是因为PATH中没有设置当前目录作为查找路径造成的。这时要执行程序,就要指明程序所在的路径,用./a.out来执行。unix下的目录级数可以很多,名字也很长。如果每个命令都要你指明路径,难道不是很麻烦吗?让计算机为我们做这些事是最好的了。PATH就是用来做这个的。
但要记住,计算机没有那么智能。QTDIR必须指定到qt所在的目录。如果你的qt所在的目录是/usr/local/qt,则QTDIR就应该设置成/usr/local/qt,如果是有版本号的,如/usr/local/qt-3.1.1,则QTDIR的内容与要与之保持一致。
发表于 2003-8-16 15:42:15 | 显示全部楼层
/* exitbutton.cpp */
#include <qapplication.h>
#include <qpushbutton.h>
#include <qstring.h>

int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    QString string("Exit");
    QPushButton *button = new QPushButton(string,NULL);
    QObject::connect(button,
            SIGNAL(clicked()),&app,SLOT(quit()));
    button->setGeometry(0,0,80,50);
    button->show();
    app.setMainWidget(button);
    return(app.exec());
}
试试。
卖本Qt/KDE2编程宝典
 楼主| 发表于 2003-8-16 20:27:11 | 显示全部楼层

qt.pro

######################################################################
# Automatically generated by qmake (1.02a) Sat Aug 16 18:26:49 2003
######################################################################

TEMPLATE = app
CONFIG -= moc

# Input
SOURCES += hello.cpp
这是我的.pro文件
 楼主| 发表于 2003-8-16 20:33:49 | 显示全部楼层

qt

我的qt 是在/usr/lib/qt-3.0.3
我在/etc/profile
中加入了
export QTDIR=/usr/lib/qt-3.0.3
export PATH=$PATHQTDIR/bin
还是不行
我还有一个问题
就是如果我自己装的mysql的话 启动要在/bin下 ./mysql
而系统安装是就选的话随便在那里mysql就可以就不要加./
。/表示在当前目录
这和./a.out   a.out是不是一会事
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表