mercoledì 21 febbraio 2018

Install Boost libraries x86 and x64 in Windows

It looks like Boost will be my daily bread in the next months.
So I've begun to implement some small examples to understand better how it works.
First problem: I have some applications developed for both 32-bit and 64-bit architecture and I've already some libraries compiled for both the architecture into two different directories.
What can we do to accomplish the same requirements? Very easy.
Download one of the available zip files from www.boost.org
Unzip it
Open Command Prompt and enter into the unzipped directory
Run bootstrap.bat (read the documentation if you need particular libraries to include)
I am using Visual C++ 14.0 for the build phase. So:
Run b2.exe install --prefix=<libs_dir>\win_x86\boost --build-dir=build/x86 address-model=32 threading=multi --build-type=complete --stagedir=<libs_dir>\win_x86\boost\x86 --toolset=msvc-14.0 -j 4
Run b2.exe install --prefix=<libs_dir>\win_x64\boost --build-dir=build/x64 address-model=64 threading=multi --build-type=complete --stagedir=<libs_dir>\win_x64\boost\x64 --toolset=msvc-14.0 -j 4

venerdì 17 luglio 2015

Creation of a custom project wizard in Qt Creator

Smart teams of developers are used to define a set of guidelines related to the style of the code: indentation, comments, conventions for the names of variables, functions, classes and so on.
This ensures a quick comprehension of code written by a developer to the other members of the team along the code reviews, tests, ...
Qt Creator supports this approach in some ways.
This post is the first of two about the creation of wizards in this IDE which will help you to deliver code in faster ways.
I'm going to describe a typical situation we developers are facing when we need to begin to implement a new GUI project.
The classical literature of the design patterns suggests to use the MVC approach (Model-View-Controller). The exhaustive explanation of this pattern is out-of-topic for this post but, in brief, we are going to:
1) create a Qt project: I suggest a "Qt Widgets Application" so we have, at least, a base window on which we can start to develop.
2) create a directory for each element that compounds the pattern: one directory for the Model, one for the View and one for the Controller;
3) create an additional directory called Utils that holds others classes/files that are not part of the pattern;
4) create a .pri file for each of these directory with the same name of the directory

We will see this:






5) move all the files related to the window into the View directory.
6) modify the .pro file in this way:



















7) run qmake from the menu Build. We should see:
 











8) right click the View directory and "Add existing files" to include the files related to the mainwindow










9) run the project to test if everything works (it should)
10) create an xml file int the project directory called wizard.xml:

11) provide an optional icon (see the above picture)
12) copy the entire project directory to <QtCreator install dir>\share\qtcreator\templates\wizards
13) restart Qt Creator
14) create a new project. We should see:













That's all.

This project is hosted in Github:
https://github.com/sassi67/qt4mvc

For additional informations please refer to the official documentation:
http://doc.qt.io/qtcreator/creator-project-wizards.html

In the next post I'm going to examine a wizard to create a custom wizard for a class.

lunedì 12 gennaio 2015

How to manage only one instance of a running executable with Qt framework

A typical issue is when you are dealing with an application in which we have to ensure that only a single instance of it is running on the current machine.
I've been doing C and C++ software development for many years especially under Windows and an efficient solution is the usage of a named mutex.
The problem is: this is not a cross-platform solution (or better, you can't write once, deploy everywhere).
Searching a solution in Internet I've found inYotube the channel of Brian Cairns (VoidRealMs, while his website is http://www.voidrealms.com/). He has produced more than 100 video tutorials about Qt framework and one of them is his solution to this problem (if you are Qt beginner I suggest you to spend some time ).
He used an IPC approach with QLocalServer / QLocalSocket.


I want to suggest a simpler solution based on QSharedMemory.
You will find an example on my GitHub account.