简体   繁体   English

使Qt在Fedora 12中工作

[英]Getting Qt to work in Fedora 12

Qt is installed by default in Fedora 12. Tried the hello world program: 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();
}

With normal compilation g++ -o helloWorld helloWorld.cpp, it shows: 使用常规编译g ++ -o helloWorld helloWorld.cpp,它显示:

/tmp/ccfEv7zR.o: In function main': helloWorld.cpp:(.text+0x2a): undefined reference to QApplication::QApplication(int&, char**, int)' helloWorld.cpp:(.text+0x53): undefined reference to QPushButton::QPushButton(QString const&, QWidget*)' helloWorld.cpp:(.text+0x8b): undefined reference to QApplication::exec()' helloWorld.cpp:(.text+0x99): undefined reference to QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xc0): undefined reference to QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to QApplication::~QApplication()' /tmp/ccfEv7zR.o: In function QString::QString(char const*)': helloWorld.cpp:(.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x1d): undefined reference to QString::fromAscii_helper(char const*, int)' /tmp/ccfEv7zR.o: In function QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to QString::fre /tmp/ccfEv7zR.o:在函数main': helloWorld.cpp:(.text+0x2a): undefined reference to QApplication :: QApplication(int&,char **,int)的main': helloWorld.cpp:(.text+0x2a): undefined reference to helloWorld.cpp :(。text + 0x53) :未定义引用QPushButton::QPushButton(QString const&, QWidget*)' helloWorld.cpp:(.text+0x8b): undefined reference to QApplication :: exec()'helloWorld.cpp :(。text + 0x99):未定义引用到QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to QPushButton :: QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to helloWorld.cpp :(。text + 0xc0):对QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to 〜QApplication的未定义引用QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to QApplication :: QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to /tmp/ccfEv7zR.o:在函数QString::QString(char const*)': helloWorld.cpp:(.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x1d): undefined reference to QString :: fromAscii_helper(char const *,int)'/tmp/ccfEv7zR.o:在函数QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to 〜QString QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to QString :: fre的QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to e(QString::Data*)' collect2: ld returned 1 exit status bash: ./helloWorld: No such file or directory e(QString :: Data *)'collect2:ld返回1退出状态bash:./helloWorld:没有这样的文件或目录

and with

qmake -project;qmake;make qmake -project; qmake; make

it shows: 表明:

/usr/lib64/qt-3.3/bin/moc /usr/include/QtGui/qapplication.h -o /usr/include/QtGui/moc_qapplication.cpp moc: Cannot create /usr/include/QtGui/moc_qapplication.cpp make: * [/usr/include/QtGui/moc_qapplication.cpp] Error 1 /usr/lib64/qt-3.3/bin/moc /usr/include/QtGui/qapplication.h -o /usr/include/QtGui/moc_qapplication.cpp moc:无法创建/usr/include/QtGui/moc_qapplication.cpp使: * [/usr/include/QtGui/moc_qapplication.cpp]错误1

Any idea how to get it to work? 知道如何使其工作吗?

UPDATE: 更新:
My cpp was already in a non-read-only directory. 我的cpp已经在非只读目录中。 Now I changed the header to 现在我将标题更改为

#include <QApplication>
#include <QPushButton>

and it shows this error: 它显示此错误:

g++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DQT_NO_DEBUG -I/usr/lib64/qt-3.3/mkspecs/default -I. g ++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE = 2 -fexceptions -fstack-protector --param = ssp-buffer-size = 4 -m64 -mtune = generic -DQT_NO_DEBUG- I / usr / lib64 / qt-3.3 / mkspecs / default -I。 -I. -一世。 -I/usr/lib64/qt-3.3/include -o helloWorld.o helloWorld.cpp -I / usr / lib64 / qt-3.3 / include -o helloWorld.o helloWorld.cpp
helloWorld.cpp:1:25: error: helloWorld.cpp:1:25:错误:
QApplication: No such file or QApplication:没有此类文件或
directory helloWorld.cpp:2:24: error: 目录helloWorld.cpp:2:24:错误:
QPushButton: No such file or directory QPushButton:没有这样的文件或目录
helloWorld.cpp: In function 'int helloWorld.cpp:在函数'int中
main(int, char* )': helloWorld.cpp:7: main(int,char * )':helloWorld.cpp:7:
error: 'QApplication' was not declared 错误:未声明“ QApplication”
in this scope helloWorld.cpp:7: error: 在此范围helloWorld.cpp:7:错误:
expected ';' 预期的';' before 'app' 在“应用”之前
helloWorld.cpp:8: error: 'QPushButton' helloWorld.cpp:8:错误:“ QPushButton”
was not declared in this scope 在这方面没有申明
helloWorld.cpp:8: error: expected ';' helloWorld.cpp:8:错误:预期为';'
before 'hello' helloWorld.cpp:9: 在“ hello” helloWorld.cpp:9之前:
error: 'hello' was not declared in 错误:未在其中声明“ hello”
this scope helloWorld.cpp:10: error: 此范围helloWorld.cpp:10:错误:
'app' was not declared in this scope 未在此范围内声明“ app”
helloWorld.cpp: At global scope: helloWorld.cpp:在全球范围内:
helloWorld.cpp:5: warning: unused helloWorld.cpp:5:警告:未使用
parameter 'argc' helloWorld.cpp:5: 参数'argc'helloWorld.cpp:5:
warning: unused parameter 'argv' make: 警告:未使用的参数“ argv”使:
* * [helloWorld.o] Error 1 * * [helloWorld.o]错误1

The problem is that /usr/include/QtGui/ is "protected" . 问题在于/ usr / include / QtGui /是“受保护的” (You do not have write permissions to that directory) (您没有对该目录的写权限)

Move your helloworld.cpp to a directory that you have write access to. 将helloworld.cpp移至您具有写访问权的目录。 For example /home/ yourusername /helloworld/helloworld.cpp 例如/ home / yourusername /helloworld/helloworld.cpp

Change: 更改:

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

To: 至:

#include <QApplication>
#include <QPushButton>

Then try: 然后尝试:

qmake -project
qmake
make

I suggest you read a bit up on using qmake . 我建议您阅读有关使用qmake的内容 You will then understand why you had the first error: qmake helps you to get the includes and right libraries step by creating a Makefile for you. 然后,您将理解为什么会遇到第一个错误:qmake通过为您创建一个Makefile来帮助您获取包含和正确的库步骤。

Edit: 编辑:

Another thing to check is to ensure qmake is in your path and optionally if the QTDIR environment variable is set. 要检查的另一件事是确保qmake在您的路径中,并且可以选择是否设置了QTDIR环境变量。

From your compile log it's clear that you're using Qt 3.3. 从编译日志中可以清楚地看到您正在使用Qt 3.3。

This explains why you still can't get it to work. 这解释了为什么您仍然无法使它正常工作。 The CamelCase-style headers, like QPushButton, were introduced in Qt 4.0. Qt 4.0中引入了CamelCase样式的标头,例如QPushButton。

Most likely you've used Qt 3.3 by accident. 您很可能是偶然使用Qt 3.3的。 Make sure that you run the qmake from Qt 4. On many Linux distributions this is installed as qmake-qt4 . 确保从Qt 4运行qmake。在许多Linux发行版中,它以qmake-qt4形式安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM