Still working with tutorials...
-
If you use QtCreator to create a new project, it will create some files for you:
for an executable:
- a main.cpp
- a class.cpp
- a class.h
where class represents the main class of your application (could be QMainWindow derived, QDialog derived, QWidget derived). Why should you create a project without knowing, which type of main window you need? And if you really don't know:
delete the classes after creation.The normal way is, create a project and create the source files in the project.
-
You have some choices:
1. let Qt Creator create a new GUI project for you
This basically creates a .pro file, a main.cpp and a form.h + form.cpp (and maybe a form.ui if you want). You must know in advance what type your form will be (Widget, Dialog, MainWindow), but you can always change afterwards2. let Qt Creator create a new console application for you
This creates a .pro and main.cpp, but no form files and disables the GUI in the .pro file. You will have to remove the "QT -= gui" from the .pro file if you want to add GUI classes afterwards.3. do it yourself
create the .pro file and main.cpp manually and open the .pro in Qt CreatorIf you are not sure what's the best option for you - just play around. Create new projects from either option and look what's in there. This way you learn much more than from asking "what should I do". It's the same path as with learning how to ride a bicycle: you can read a thousand books on it but you will learn it only by try and error.
Since you are still in the learning phase of the tools: just go ahead and click on the buttons. If you trash your project, delete it and start over from scratch. No animals will be harmed in this process :-)
[EDIT formatting, Volker]
-
I recommend not to use any IDE at the start at all. If you do it by hand, you actually can learn how it works from the low level, get used to commands Qt is using and feel comfortable if you ever need to do something in different environment than the one you are mostly working on.
For example, type / copy the example file, go to command line, run qmake -project, qmake, make and run the binary.
Then you could try to understand what those steps actually do... And after it, depending of the type of the project you have, adjust your workflow towards that, and make Qt usable there.
-
[quote author="Gerolf" date="1295248677"]If you use QtCreator to create a new project, it will create some files for you:
for an executable:
- a main.cpp
- a class.cpp
- a class.h
where class represents the main class of your application (could be QMainWindow derived, QDialog derived, QWidget derived). Why should you create a project without knowing, which type of main window you need? And if you really don't know:
delete the classes after creation.The normal way is, create a project and create the source files in the project.[/quote]
OK, here's a very simple example of what I'm talking about. I found this demo somewhere:
@#include <QApplication>
#include <QPushButton>int main(int argc, char *argv[])
{
QApplication app(argc, argv);QPushButton hello("Hello world!"); hello.resize(100, 30); hello.show(); return app.exec();
}
@So...assuming I wanted to create a project for this, what would be the recommended method? I don't have a .h file; it's all self contained.
-
Hey, Volker –
Thanks for the answer. So, if I infer from you correctly, the only essentials are a source file and a project file? Is there some information online specifically about the project file syntax? Perhaps I'll take smar's advice and begin from the command line, though it isn't my first choice.
-
Yepp, that's enough. For your little project consisting of a main.cpp and nothing else, you only need a .pro file. You can create one by calling
@
qmake -project
@in the directory containing the main.cpp.
See the "Getting Started Programming with Qt":http://doc.qt.nokia.com/latest/gettingstartedqt.html, it explains how to do this. Translations into various languages are available in the "wiki":http://developer.qt.nokia.com/wiki/Category:Learning::GettingStarted.
Once you have a .pro file, just open it in Qt Creator (using the file menu or Ctrl-O/Cmd-O) and you're done. No need to create a new project in this case.
-
OK...so I created a directory, created a source file and a .pro file. I ran qmake on the .pro file, and now I have this:
@
-rw-r--r-- 1 mzimmers mzimmers 594 Jan 17 14:15 Info.plist
-rw-r--r-- 1 mzimmers mzimmers 542 Jan 17 14:00 hello.cpp
-rw-r--r-- 1 mzimmers mzimmers 32 Jan 17 14:15 hello.pro
drwxr-xr-x 5 mzimmers mzimmers 170 Jan 17 14:15 hello.xcodeproj
@No binary file...so, now I have to run regular make, I guess?
[EDIT: markup, Volker]
-
If you want to continue on the command line then this "wiki article":http://developer.qt.nokia.com/wiki/Generate_Makefiles_instead_of_XCode_projects_on_Mac_OS_X will help you.
If you want to use Qt Creator, just open the .pro file in Creator, it runs qmake for you.
-
Really? Just opening the .pro file causes qmake to run?
Also, from one of the instructional videos (which might be out of date by now), I got the impression that one needed to run qmake, then run make. True or not?
I'm also curious: is it OK to go back and forth between a CLI and Creator for a particular project, or is it better to choose one and stick to it?
Thanks.
-
[quote author="mzimmers" date="1295304369"]
I'm also curious: is it OK to go back and forth between a CLI and Creator for a particular project, or is it better to choose one and stick to it?Thanks.[/quote]
It’s best to learn both. You can go around with only one. Your pick, and your timeline and interest what you actually want to accomplish :)
-
[quote author="Smar" date="1295304606"]
[quote author="mzimmers" date="1295304369"]
I'm also curious: is it OK to go back and forth between a CLI and Creator for a particular project, or is it better to choose one and stick to it?Thanks.[/quote]
It’s best to learn both. You can go around with only one. Your pick, and your timeline and interest what you actually want to accomplish :)[/quote]
What I meant was, for a particular project...is it best to use only one of the two interfaces, or can you flip-flop without repercussions? Put another way...is the CLI compatible with Creator and the other GUI tools?
Thanks.
-
[quote author="mzimmers" date="1295304369"]Really? Just opening the .pro file causes qmake to run?
Also, from one of the instructional videos (which might be out of date by now), I got the impression that one needed to run qmake, then run make. True or not?
I'm also curious: is it OK to go back and forth between a CLI and Creator for a particular project, or is it better to choose one and stick to it?
Thanks.[/quote]
Qt Creator calls qmake and make for you, captures the output and can bring you to the point in the code where the error happened.
It is perfectly ok to switch between CLI and Creator. Although you should keep in mind that the shadow builds, that Creator enables by default, reside in another directory. You should know what you're doing, otherwise you can mess up thing.
-
[quote author="mzimmers" date="1295304889"]
What I meant was, for a particular project...is it best to use only one of the two interfaces, or can you flip-flop without repercussions? Put another way...is the CLI compatible with Creator and the other GUI tools?
[/quote]Shortly: yes.
-
Shadow builds...that's a term I haven't come across yet. I assume that is for some default target that Creator keeps track of? I've done some tutorials that have resulted in subdirectories like tutorial6 AND tutorial6-build-desktop...is this what you're talking about? Oddly enough, it doesn't happen all the time.
Also, per the Wiki you cited above: I don't seem to have a mkspecs directory anywhere. Was I supposed to create this myself?
Thanks.
-
A shadow build is a build setup and cycle (creating intermediate and object files as well as the final executable or lib) in an directory outside your source tree.
Regarding the wiki article: You do have the dir somewhere, it's where your Qt libs are installed. The actual directory depends on your installation.
-
[quote author="Volker" date="1295307950"]Regarding the wiki article: You do have the dir somewhere, it's where your Qt libs are installed. The actual directory depends on your installation.
[/quote]I've done a search on my entire HD for a file/directory with that name...nothing. I wonder if I botched something in the installation?
-
[quote author="mzimmers" date="1295308733"]
I've done a search on my entire HD for a file/directory with that name...nothing. I wonder if I botched something in the installation?[/quote]No, it must be on your HD otherwise qmake would not work at all. You can try
@
locate mkspecs
@in the shell (CLI).
-
You want to generate XCode projects when you want to work with the XCode IDE.