让Qt在Fedora 12中工作

Getting Qt to work in Fedora 12

本文关键字:工作 Fedora Qt      更新时间:2023-10-16

Qt默认安装在Fedora 12中。试过hello world程序:

 #include </usr/include/QtGui/QApplication>
 #include </usr/include/QtGui/QPushButton>
 int main(int argc, char *argv[])
 {
   QApplication app(argc, argv);
   QPushButton hello("Hello world!");
   hello.show();
   return app.exec();
}

使用正常编译g++ -o helloWorld helloWorld.cpp,它显示:

/tmp/ccfEv7zR。0: In function main': helloWorld.cpp:(.text+0x2a): undefined reference to QApplication::QApplication(int&;char * *, int) 'helloWorld.cpp:(。text + 0 x53):定义参考QPushButton::QPushButton(QString const&, QWidget*)' helloWorld.cpp:(.text+0x8b): undefined reference to QApplication: exec()"helloWorld.cpp:(。text + 0 x99):定义参考QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to QPushButton:: ~ QPushButton()"helloWorld.cpp:(。text + 0 xc0):定义参考QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to QApplication:: ~ QApplication()"/tmp/ccfEv7zR。0:在使用中QString::QString(char const*)': helloWorld.cpp:(.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x1d): undefined reference to QString:: fromAscii_helper (charconst*, int)'/tmp/ccfEv7zR。o:function QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to QString::free(QString::Data*)'Collect2: ld返回1退出状态bash: ./helloWorld:没有这样的文件或目录

qmake项目;qmake;使

显示了

:

/usr/lib64/qt - 3.3/bin/商务部/usr/include/QtGui/qapplication.h - o/usr/include/QtGui/moc_qapplication.cppmoc:不能创建/usr/include/QtGui/moc_qapplication.cpp: * (/usr/include/QtGui/moc_qapplication.cpp)错误1

知道怎么让它工作吗?

更新:
我的cpp已经在一个非只读目录中。现在我把标题改为

#include <QApplication>
#include <QPushButton>

显示如下错误:

g++ -c -pipe -Wall -W -O2 -g -pipe——参数=ssp-buffer-size=4——m64 -mtune=generic——dqt_no_debug -I/usr/lib64/qt-3.3/mkspecs/default -I。-我。-I/usr/lib64/qt-3.3/include -o helloWorld。o helloWorld.cpp
helloWorld.cpp: 1:25:错误:
应用程序:没有这样的文件或
目录helloWorld.cpp:2:24:错误:
QPushButton:没有这样的文件或目录
helloWorld.cpp: In function ' int
main(int, char*) ': helloWorld.cpp:7:
错误:未声明' QApplication '
helloWorld.cpp:7: error:

<应用程序>helloWorld.cpp:8: error: ' QPushButton '
未在此作用域
声明helloWorld.cpp:8: error: expected '; '
before ' hello ' helloWorld.cpp:9:
错误:
中没有声明' hello 'helloWorld.cpp:10:错误:
' app '未在此范围内声明
helloWorld.cpp:在全局范围内:
helloWorld.cpp:5:警告:未使用
参数' argc ' helloWorld.cpp:5:
警告:未使用的参数argv make:
*
* [helloWorld。0]错误1

问题是/usr/include/qtgui/是"protected"。(您没有对该目录的写权限)

将helloworld.cpp移到您具有写访问权限的目录中。例如:/home/yourusername/helloworld/helloworld.cpp

改变:

#include </usr/include/QtGui/QApplication>
#include </usr/include/QtGui/QPushButton>

:

#include <QApplication>
#include <QPushButton>

然后尝试:

qmake -project
qmake
make

我建议你读一点关于使用qmake。然后你就会明白为什么会出现第一个错误:qmake通过为你创建一个Makefile来帮助你获得包含和正确的库步骤。

编辑:

另一件要检查的事情是确保qmake在您的路径中,如果设置了QTDIR环境变量,则可以选择qmake。

从你的编译日志很明显,你正在使用Qt 3.3。

这就解释了为什么你仍然不能让它工作。camelcase风格的头文件,比如QPushButton,是在Qt 4.0中引入的。

很可能你无意中使用了Qt 3.3。确保从Qt 4运行qmake。在许多Linux发行版中,它安装为qmake-qt4