让Qt在Fedora 12中工作
Getting Qt to work in Fedora 12
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:functionQString::~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
。
- QSqlquery prepare()和bindvalue()不工作
- cmake如何在fedora工作站中找到boost静态库包
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 有人能解释一下为什么下界是这样工作的吗C++的
- ExtractIconEx:可以工作,但偶尔会崩溃
- C++中的memset函数工作不正常
- qDebug() 在升级到 ubuntu 17.10(和 Fedora)后停止工作(不再打印到控制台)
- 让Qt在Fedora 12中工作