我可以在没有 qmake 或 Qt Creator 的情况下使用 Qt 吗? [英] Can I use Qt without qmake or Qt Creator?

查看:57
本文介绍了我可以在没有 qmake 或 Qt Creator 的情况下使用 Qt 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Qt 编程,但我不想使用特殊的编译器或 IDE,例如 Qt Creator 和 qmake.我想和 Kate 一起写,用 g++ 编译.

I want to program using Qt, but I don't want to use special compilers or IDE such as Qt Creator and qmake. I want to write with Kate and compile with g++.

我可以用g++编译一个使用Qt的程序吗?我如何用 g++ 编译它?

Can I compile a program that uses Qt with g++? How do I compile it with g++?

推荐答案

当然可以.虽然用 qmake 或 CMake 更方便,但你可以这样做:

Sure you can. Although it is more convenient with qmake or CMake, you can do:

CXXFLAGS += -Ipath_to_your_qt_includes
LDFLAGS += -Lpath_to_your_qt_libs

LDLIBS += -lqt-mt (for Qt3)

LDLIBS += -lQtCore -lQtGui (for Qt4, add what you need)

my_prog: my_prog.cpp

(在生成文件中)

更新 - 调用 moc:

引用自 moc 手册页:

这是一个有用的 makefile 规则,如果您只使用 GNU make:

Here is a useful makefile rule if you only use GNU make:

m%.cpp: %.h
        moc $< -o $@

我个人将输出命名为 %.moc.cpp(而不是 m%.cpp).然后将 my_prog 的依赖添加到 my_prog.moc.cpp

I'd personally name the output rather %.moc.cpp (than m%.cpp). You then add the dependency of my_prog on my_prog.moc.cpp

my_prog: my_prog.cpp my_prog.moc.cpp

同样适用于 uic.这里的情况更复杂,因为你必须为头文件生成规则,并且你必须添加对头文件的依赖以确保它在源代码编译之前生成.像这样的事情可能会奏效:

Similarly for uic. The situation here is more complicated, since you have to generate rules for headers and source files, and you have to add a dependency on a header file to ensure it gets generated before the sources are compiled. Something like this might work:

my_prog: my_prog.o my_prog.moc.o my_prog.ui.o
        $(CXX)  $(LDFLAGS) -o my_prog $^ $(LDLIBS)

my_prog.o: my_prog.cpp my_prog.ui.h

这篇关于我可以在没有 qmake 或 Qt Creator 的情况下使用 Qt 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆