Tuesday, July 5, 2011

NSIS Installer für QT Projekte

Hello,
as I promised in the last post, this time I'm on the subject of intense NSIS Installer one. The NSIS (Nullsoft Scriptable Install System) is very highly configurable and therefore can script are great. I occupied myself with this issue now and wrote a first script, with input from existing install scripts aimed at facilitating the creation of Setup.exe.
That's what I tried to reach where I work at the beginning of this script with a lot of variables. But enough of introduction, here is the script with the appropriate explanations.
The installer is back for the address book example of Qt.

!Define PRODUCT_NAME "AddressBook sample"
Name "$ {PRODUCT_NAME}"
!Define EXE_NAME "part2.exe"
!Define PRODUCT_VERSION "0.2"
!Define VER_MAJOR 0
!Define VER_MINOR 2
!Define VER_REVISION 2
!Define VER_BUILD 10
!Define PRODUCT_PUBLISHER "Jürgen Mülbert"
!Define PRODUCT_WEBSITE 
    "http://www.juergen-muelbert.de"
!Define PRODUCT_SUPPORT_SITE 
    "http://www.juergen-muelbert.de/support.html"
!Define PRODUCT_DIR_REGKEY 
    "Software\Microsoft\Windows\CurrentVersion\
     App Paths\${EXE_NAME}"
!Define PRODUCT_UNINST_KEY 
   "Software\Microsoft\Windows\CurrentVersion\
    Uninstall\${PRODUCT_NAME}"
! Define REG_KEY "SOFTWARE\$(^Name)"
! Define HKLM INSTALL_ROOT_KEY
 
Most of the definitions shown above are self-explanatory HKLM is the RegistryKey for the "local machine". Otherwise your request ...

;--------------------------------
; Configuration
Caption "$ {PRODUCT_NAME} $ {PRODUCT_VERSION} Setup"
branding text "© Jürgen Mülbert"
!Ifdef OUTFILE
OutFile "$ {OUTFILE}"
!Else
OutFile 
   ..\${PRODUCT_NAME}-${PRODUCT_VERSION}-setup.exe
!Endif
; Installer attributes
InstallDir $PROGRAMFILES\${PRODUCT_NAME}
InstallDirRegKey 
   ${INSTALL_ROOT_KEY} "${PRODUCT_DIR_REGKEY}" ""
 
As seen here, in the above text is already used extensively to access the configuration defined constants. That runs through the entire file, as we shall see at the next example.

;--------------------------------
; Installer Sections
Section! $(Secmain) secmain

SetDetailsPrint TextOnly
detailed print "Installing $ {PRODUCT_NAME} core files ..."
SetDetailsPrint listonly
SectionIn 1 2 3 RO
SetShellVarContext all
SetOutPath $ INSTDIR
SetOverwrite on
$ {File} EXE_NAME
Changelog.txt file
File libgcc_s_dw2-1.dll
File mingwm10.dll
File QtCore4.dll
File QtGui4.dll
File addressbook_de.qm

WriteRegStr 
   ${INSTALL_ROOT_KEY} "${REG_KEY}\Components" sec_main 1
SectionEnd
 
Here is an example of the last main section is listed. In this section, all necessary components installed so the program can run at all. How beautiful is seen here appears as a variable of PRODUCT_NAME . Although that is only used for the detail log, but still. The INSTALLDIR is finally initialized with the PRODUCT_NAME and the much earlier. Incidentally, the command SetShellVarContext with the all option sets, the set this installation for all users of this computer implemented. SetOverwrite on causes all existing files are overwritten by the files in the installation archive. The next variable is used EXE_NAME , which simply contains the name of the executable program. The contents of the file changelog.txt will be displayed after the installation:
!define MUI_FINISHPAGE_SHOWREADME $INSTDIR\changelog.txt
!define MUI_FINISHPAGE_SHOWREADME_TEXT changelog.txt
The DLL's are required. These are the two DLL's was compiled with the QT. Without the use Qt libraries, it would not work of course. At the end of the file list still stands, the translation file for the German text of the address book example. At the end of this section is not written in the Windows registry that the main components were installed.
As I said the moves so through the entire script, which is seen to be fully compatible with link . On my website there are now projects JMNSISHelper NSIS4Java about this topic.

Monday, June 20, 2011

QT and CMake

Dear Readers,

I now after some experience with C + + and qmake have made I want to tell you about something new. I create the theme of trying out the programs CMake to address visibility. I always like to try something new. But it is really in this case so CMake is better and has other advantages over qmake .

CMake is not only suitable for QT.
CMake also includes support for installers.
CMake finds support from the system-installed packages and scripting languages.

Of course, even a little shade is available. Such a package can not only shine. However, the shortcomings I have found and over which I stumbled at the start'm not caused by CMake. The problem lies in the Windows version of QT GPL package. In this version is a "mingw32-make" with the CMake does not work. Who wants it exactly as I try to QT-Windows with CMake must first addition to the MINGW in the current install version. The newly installed version will work fine.
To simplify the construction of a new program it puts you on the best one on the BATCH file that sets environment variables. The alternative would be to add work to the appropriate paths in PATH. I have only
 "C:\MinGW\ bin"  
is registered to the GUI version of CMake also the compiler. The remaining paths are set in a script that I
"CMakeShell.bat" 
. It is not the most creative name, but he hits it exactly. This file contains the paths to the QT directory to the MinGW directory and the directory will be set CMake. Anyone can file this simple little need to expand:

 echo Setting up a MinGW / Qt only environment ...
set QTDIR = C:\Qt\2010.05\qt
set CMAKEDIR = "C:\Program Files\CMake 2.8"
set MINGWDIR = C:\MinGW
set PATH = %PATH%;C:\Qt\2010.05\
set PATH =%PATH%;%QTDIR%\bin;%MINGWDIR%\bin;%CMAKEDIR%\bin
set PATH =%PATH%;%systemroot%\system32
 

Now you must note that not only the batch script is executed directly. That would only cause the a DOS window for a moment on the screen shows only to disappear again. The trick here is to create a new shortcut. This link must then begin to target this:
 "C:\WINDOWS\system32\cmd.exe / K"  
. Directly after the space then follows the path to the batch script.

So and now a lot of fun with testing CMake. I will write about this topic here a little too soon.

CMake for packages


Hi,
As already described in previous entries CMake is very versatile. Unlike it can be used for all types use of projects. It is not tied to an environment.

CPack

As an additional feature, the developers have even integretad a package builder. With this, in the normal range of programs is included, additional module you can simply grab the current project. As might be expected to provide CMake are many targets for different environments available.

Archive

It can generate archives:
  • TGZ - Tar with GnuZIP
  • STGZ - Selbstenpakendes TGZ
  • tbz2 - Tar BZip2 with (an archive is compressed, the better)
  • TZ - with Tar Compress
  • ?
  • ZIP - For the Windows environment. It must be installed 7Zip or WinZip.

Windows

For the Windows environment is a generator. Also can be generated for the Cygwin Environment Binary and source packages.

Mac

For the OSX environment, these archives are generated:
  • DragDrop
  • PackageMaker - PackageMaker must be installed
  • .
  • OSXX11 - hdiutil must be installed
  • .
  • bundle

Linux

For Unix, both Debian (DEB), as well as RPM packages can be created. The complete description and its parameters are in the WIKI by CMake to find.

How it works

But how this feature can be invoked? That's easy. The CMakeLists.txt file must be added just one line.
INCLUDE (CPack)
This is not only an additional text file named CPackList.txt but also creates a new target in the Makefile . Calling
 make package  
for the current environment is defined standard package generates. These options should be determined in the CMakeLists.txt file. You can thereby specify according to the CMake known as syntax, the system generates the packet. Moreover, even the variables are filled in even when you call:
 cmake DCPACK_GENERATOR = DEB  
would create a Debian package.This is all simply and easily by hand. a warning but still . The emphasis here is really easy. Huge and complicated package, with this function of course does not generate too easy. Operate here, the package manager or the programmers understandably more effort. A simple example is here to find.

Saturday, June 18, 2011

External or QT translations in the program

Alternatives


The QT package offers two ways to integrate the translated text into the program.

Method 1 (like Linux)


In an external file. This file contains the localized strings. For each language a file is necessary. Typical is the collection of these files in the directory translations . In the program, the file main.cpp is the code:


.

QString locale = QLOCAL:: system (), name ();

QTranslator translator;
translator.load (QString ("translations" +
QDir:: separator () +
"Jmnsishelper_") + locale);
a.installTranslator (& translator);


to the translation of the load required. The first line will be determined in what kind of a localization program currently is doing its job. The result is stored in the variable locale. This variable contains a string that de for Germany is . This string is then appended to the filename. The newly formed string that contains the file name will now pass the class QTranslator . The information contained in the library functions then take care of the rest

Method 2 (Windows-like)


The second possibility is the translation available as a resource. This is with the LRelease generated m file required. This file is then converted to C + + code. This code is compiled and then linked with the other source code files for a program to be.

Add the translations for a QRC file is needed:


jmnsishelper_de.qm
jmnsishelper_es.qm
jmnsishelper_it.qm
jmnsishelper_tr.qm



The resource looks like this:
 
static const unsigned char  qt_resource_data [] = {
   0x0, 0x0, 0xa, 0x55, 
 0x3c, 
 0xB8, 0x64, 0x18, 0xCA, 0xEF, 0x9c, 0x95, ...
because they have always dated qmake tool, or with better < produces CMake must be done is (thankfully) nothing here.
The source of main.cpp also looks different.
 
 QString lang = QLOCAL::. system () name ();
 
 QTranslator translator; 
 translator.load ("jmnsishelper_" + long, ": / ts /");
 a.installTranslator (& translator); 

Advantages and disadvantages


The second option simplifies the compilation of the package. Also you can save yourself a subdirectory. Also in the main.cpp written source code is shorter. However, this method has drawbacks. If the translation has been brought up to date, the program is to compile complete and to the left. In this method one can simply qm file in translations replace. There is also, at least for Linux and the tools that m file to read. This is not according to the method two.