Still working with tutorials...
-
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.