If you have read my last tutorial, you have gotten a basic understanding of C++ and/or Qt. I also said that we we're gonna discuss how to make a GUI, but I'm sorry, theres still more I have to explain before we get to that. In this tutorial, I will be explaining a bit of Platform Specific code. In my own words, Platform Specific code is code that runs only on certain platforms. Examples of platforms are:
- Windows (Vista, XP, 7, 2000, etc)
- Mac OS X (10.1, 10.2, 10.3, etc) 'I forgot the names.
- Linux (Ubuntu, Sabayon, Debian)
- Unix
Question 1: What do I do if Qt isn't available for my platform?
Well...I'm not sure, but from what I've heard, its easy to port Qt another platform, but I doubt there isn't a version for your platform.
Question 2: Can I use Qt to program on phones?
YES!!! Qt is also available for phones and embedded systems.
Question 3: Is it free to distribute Qt applications?
Yes! Under the LGPL license, you have to make source-code available if your use Qt for Free, or else you have to pay big $$$.
Question 4: How do i get a makefile?
Included in Qt is a tool called QMake, which takes your Qt Creator project file (.pro) and creates a MakeFile from a set of rules in the pro file.
Coding
Now....Its time to get to discussing the code. As I said before, Qt is available on different platforms but on some of them, the impletetation isn't the same. Thats why Qt allows you to try different code depending on the platform and this is helped by QMake.
An example of your project file/Qmake file is.
#------------------------------------------------- # # Project created by QtCreator 2009-07-31T12:58:43 # #------------------------------------------------- QT -= gui TARGET = HelloWorld-DIC CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
Explanation
Heres a short explanation of some common QMake variables.
- QT = A varible that tells QMake what Modules to include in the build.
- TARGET = The output file (without the extension)
- CONFIG = Tells what the app is gonna be.
- TEMPLATE = Somewhat the same as CONFIG
- SOURCES = the source code files in the project.
- HEADERS = the headers of the project.
- FORMS = the ui files of the project.
CONFIG += qt debug
HEADERS += hello.h
SOURCES += hello.cpp
SOURCES += main.cpp
win32 {
SOURCES += hellowin.cpp
}
unix {
SOURCES += hellounix.cpp
}
Thats a example of a Qmake file that supports multi-platforms. Sounds simple huh?! It may look like it but I've still haven't got the hang of gcc on Linux, oh well.....*<- OFF TOPIC
Stopping QMake if a file doesn't exist.
All though I haven't written the code for the multi-platform qmake code, or the code below, I will give credit to Nokia and the Qt Creator help files. I haven't tested this feature myself yet, but I think it will be good to discuss this.
!exists( main.cpp ) {
error( "No main.cpp file found" )
}
Really, all that code does is checks if the file exist, and if it doesn't, it calls "error" which prints out "the file doesn't exist" and stops qmake. If you would like to print out text without stopping qmake, just use "echo" instead.
Platform Notes
Some stuff, I would like to point out are:
- Each platform uses a different compiler.
- The Qt implementation slightly differs platform to platform.
Closing
Well, this is the end of this tutorial, in the next part, will talk about some modules and the UI.






MultiQuote



|