Qt Creator: add Qt module to project

2019-01-28 11:43发布

So when I create a new Qt project inside Qt Creator I'm only asked for some simple details like location of the project, build targets, the main window class name (along with header, source and form file) and at the enda choice to add it to version control.

After I create the project I'm only given the qt core and gui modules. My question is how do I add other modules (such as network or opengl). I've looked and looked, yet I cannot find anything on how to add other Qt modules easily. I know I can edit the .pro file, but unfortunately I don't know all the modules in Qt, nevermind the name I'm supposed to put there. Adding external libraries is easy, but how come there's no (obvious) option to add Qt libraries?

Help would be much appreciated ^_^ Thanks!

Oh yeah... I'm running Arch Linux if that's any help.

4条回答
淡お忘
2楼-- · 2019-01-28 12:15

I can't find that either.

It seems that in older versions of the "New project" wizard you used to be able to specify which modules you wanted to use, but even then you were not able to alter your choice later. And this seems gone now, so your only choice is to manually edit the .pro file.

查看更多
SAY GOODBYE
3楼-- · 2019-01-28 12:15

You have to read the documentation to add the modules.

Frankly speaking, I never really felt like that there needs to be a GUI for that.

查看更多
聊天终结者
4楼-- · 2019-01-28 12:20

Edit your .pro file. It should has one line like this:

QT += core gui

Append the desired modules in this line. To get the module's names, just remove the "Qt" part in this list. (e.g. QtSql turns "sql")

查看更多
干净又极端
5楼-- · 2019-01-28 12:33

As others have pointed out, you simply #include the module you want in the source and add the name of the module in the .pro file to the QT variable.

However the actual documentation you need which no one else has mentioned is the qmake Project Files page. qmake is very powerful and it's well worth getting familiar with how it works and I think that's why they don't provide a complete GUI for it, as it can handle some very complex scenarios.

查看更多
登录 后发表回答