Wednesday, 23 October 2013

Qt with MAC OS-X - 4 simple points to know

I have been working on Qt for Mac OS-X and found it is quite different compare to Windows or Linux.
Mac is a very vast on its own and introduces many levels of security for user safety.
Let's have a look into 4 basic points about Qt in Mac OS-X.

I have used MacBook Pro, with OS X 10.8.4 and Qt version of 4.8

> Point 1 <
Qt installer comes as .DMG files, stands for Disk Image files. A DMG file is like a virtual DVD or hard drive. They can be “mounted” on your Mac in order to work with their contents, or even burned to an actual physical disc.
Right click on DMG file and chose "Open Wint >" or double click on DMG it should auto mount using DiskImageMounter, if it's your default image mounter application in Mac. Once the image is mounted, it is very easy to install Qt file from image.

> Point 2 <
Where all Qt gets installed in Mac?
This is little tough to explain. When I installed my Qt version 4.8.4, it got installed into many directories.
However, after installation, for qmake-query, I found this results,

Still it is difficult to say where all it got installed :)

> Point 3 <
How to deploy Qt application in Mac?
It is quite easy to deploy Qt applications in Mac, when it is dynamically built. Mac applications will have executable extension .APP. This .APP file is a special type of container [in other word folder] which will going to hold all Qt dependencies inside, for application to launch. Great thing is, the main executable will also be inside APP directory, here in this location,
Let's build and deploy .app for MyDemo application.
Once you are able to successfully compile Qt application, Qt creates executable for your convenience.
If in case it is not created, just run below command,
sh-3.2# otool -L
After above step is done, we need to use a tool called install_name_tool.
Let's run these build scripts,
sh-3.2# mkdir -p
sh-3.2# cp -R /Library/Frameworks/QtCore.framework
sh-3.2# cp -R /Library/Frameworks/QtGui.framework
Above two lines copy frameworks dynamic libraries into app Contents/Frameworks directory.
After copying Qt library into the bundle, we must update both the library and the executable so that they know where they can be found. This is where the install_name_tool command-line tool comes in handy. For the Qt library, run these two lines,
sh-3.2# install_name_tool  -id  @executable_path/../Frameworks/QtCore.framework/Version/4/QtCore
sh-3.2# install_name_tool  -id  @executable_path/../Frameworks/QtGui.framework/Version/4/QtGui
And for the executable,
sh-3.2# install_name_tool -change @executable_path/../Frameworks/QtCore.framework/Version/4/QtCore
sh-3.2# install_name_tool -change @executable_path/../Frameworks/QtGui.framework/Version/4/QtGui
Now that your application is ready to deploy. Just give files as executable.

> Point 4 <
How to Un-Install Qt from Mac?
This is also a tough to explain. But I did below steps to un-install Qt from my MacBook.
For all below steps to execute, you must be super-user.
sh-3.2# cd  /Applications/
sh-3.2# rm  -r*
sh-3.2# rm  -r
sh-3.2# cd  /Library/Frameworks/
sh-3.2# rm  -r  Qt*
sh-3.2# cd  ~/Library/Preferences/
sh-3.2# rm  com.qt*
sh-3.2# rm  org.qt*
sh-3.2# cd  /usr/local/
sh-3.2# rm  -r  Qt*
After all above steps, now run Qt un-installer located in /Developer/Tools/
sh-3.2# cd  /Developer/Tools/
sh-3.2# ./
This, hopefully, will going to un-install Qt successfully from your Mac Book.

Friday, 4 October 2013

Zip and Unzip with ZLib in Windows

Hi friends,
This is a quick post on 'How to use ZLIB for Zippinga and Unzipping archives in Windows'.
Nothing much to do, it's all ready available in ZLIB source. You just need to download and compile it. That's all.

I have used below configuration for my compilation:
[*] OS Type : Windows 7, 64-Bit
[*] Visual Studio 2010, Command line Compiler for 64-Bit

Before we begin, I will introduce you what's is there in ZLIB bundled.
ZLIB is a software library used for data compression. zlib was written by Jean-Loup Gailly and Mark Adler and is an abstraction of the DEFLATE compression algorithm used in their gzip file compression program. zlib is also a crucial component of many software platforms including Linux, Mac OS X, and iOS. It has also been used in gaming consoles such as the PlayStation 3, Wii, and Xbox 360.
The first public version of zlib, 0.9, was released on 1 May 1995 and was originally intended for use with the libpng image library. It is free software, distributed under the zlib license.

But ZLIB by itself doesn't support Zipping and Unzipping of archives, files and folders [refer FAQs]. It can handle only data compression. So, we need an external application to handle files and folders zipping and unzipping activity.

Fortunately, there is a package integrated inside ZLIB itself, called MiniZip, which handles all kind of archives. This comes part of ZLIB source now a days. [refer MiniZip].

So, basically, in this post, we will going to compile MiniZip source for Windows, coming with ZLIB source code.

Well let's start then.
At the time of writing this post, ZLIB latest version was zlib1.2.5.
Download ZLIB source code form >> here << or from >> here << [please inform me if link is broken]

For our compilation, we basically don't need ZLIB source code. So I will use pre-compiled ZLIB static library for my work. Download pre-compiled ZLIB libraries from >> here <<. This contains, Windows specific ZLIB DLLs and LIBs for both 64-bit and 32-bit compilation.

Unzip and keep both the directories in a common folder [for e.g, C:\TEST\zlib1.2.5 and C:\TEST\zlib125dll]

I have written a Makefile for windows 64-bit compilation. Please refer it. Download it and copy it into "C:\TEST\zlib1.2.5\contrib\minizip\" directory. The Makefile already present in minizip directory will support Linux only. So you can either keep a back-up of old Makefile or replace it with the one I have given you.

Inside minizip directory, you must find below source files,
ioapi.c, iowin32.c, zip.c, unzip.c, miniunz.c, minizip.c and corresponding header files.
minizip.c and miniunz.c are main source files for Zipping and Unzipping demo.
Open all the source files and header files, if you see below include at the top,
#include "zlib.h"
replace it with
#include "..\..\zlib.h"
as our main zlib source is two directory below the hierarchy.

Now, open "Visual Studio 2010 x64 Win64 Command Prompt" and navigate to "C:\TEST\zlib1.2.5\contrib\minizip\" directory and type command,

 nmake all
If everything goes fine, and if you have followed all the steps from above properly, it should compile perfectly and should yield 2 binaries "MyMiniZip.exe" and "MyMiniUnZip.exe"

Now it's time to test binaries,
[>] To zip any files, use MyMiniZip.exe
MyMiniZip.exe  <>  <input_file1>  <input_file2>...<input_fileN>

for e.g,(I hope no explanation is required)
MyMiniZip.exe  file1.txt  file2.jpg  subDir\file3.png  C:\MyDir\file4.doc

[>] To UnZip any zipped files, use MyMiniUnzip.exe
MyMiniUnZip.exe  <>

for e.g,
MyMiniUnZip.exe  C:\MyDir\

[>] To list all the files inside a zipped files use MyMiniUnZip.exe with -l flag
MyMiniUnZip.exe -l <> 

I hope everything went good at your side. Enjoy. :)