Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Qt without qmake or Qt Creator?

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++.

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

like image 242
Squall Avatar asked Sep 02 '10 23:09

Squall


People also ask

Can I use Qt without Visual Studio?

Yes. And even without Windows, if you don't need Windows specifically. The IDE that is shipped with Qt Framework is QtCreator.

What is the difference between Qt and QtCreator?

Qt Designer is for designing Dialogs and Main Windows (. ui files). Qt Creator is a full IDE for developing your program.

Can I use Qt with Visual Studio?

In Microsoft Visual Studio, select Extensions > Manage Extensions > Online, and search for Qt Visual Studio Tools to install or update Qt VS Tools.

Why we use QtCreator?

Qt Creator is a cross-platform integrated development environment (IDE) built for the maximum developer experience. Qt Creator runs on Windows, Linux, and macOS desktop operating systems and allows developers to create software across desktop, mobile, and embedded platforms.


2 Answers

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) 

or

LDLIBS += -lQtCore -lQtGui (for Qt4, add what you need)  my_prog: my_prog.cpp 

(in a makefile)

Update - invoking moc:

Quote from moc manpage:

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

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

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 

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 
like image 75
jpalecek Avatar answered Oct 05 '22 22:10

jpalecek


You certainly don't have to use QtCreator to write a Qt program.

You also don't have to use qmake but you are asking for trouble by not using it.

To do anything even remotely interesting in Qt you will inevitably end up subclassing QObject. All these subclasses require the Q_OBJECT macro in their definition which enables the signal/slot syntax. This syntax is not regular C++ and cannot be compiled using g++. Files containing class definitions with Q_OBJECT must be run through Qt's meta-object compiler which is called moc. This means you have to work out which files need to have moc applied to them, then run moc on them, and then compile the resulting cpp file with g++. This is the reason that Qt supplies qmake. It generates the correct rules in the Makefile for you.

Qt .pro project files are really quite straightforward to work with and I would seriously recommend that you use them. Remember, qmake is a command line tool just like g++. Also, it can actually create a skeleton project file for you by supplying the -project option so to get started you can just do

qmake -project qmake make 

and you are done. In practice I find that the generated project file may be missing the declaration of any extra Qt libraries I might be using so you might have to add a line like

QT += opengl 

if, for example, you have included something like QGLWidget.

like image 29
Troubadour Avatar answered Oct 05 '22 23:10

Troubadour