我可以使用Qt没有qmake或Qt Creator? [英] Can I use Qt without qmake or Qt Creator?
问题描述
我想使用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++.
我可以编译一个使用Qt和g ++的程序吗?如何用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
(在makefile中)
(in a makefile)
更新 - 调用 moc
:
引用 moc联机帮助页:
规则如果你
只使用GNU make:
Here is a useful makefile rule if you only use GNU make:
m%.cpp: %.h
moc $< -o $@
code>%。moc.cpp ( m%.cpp
)。然后,在 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
这篇关于我可以使用Qt没有qmake或Qt Creator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!