Topmost semi transparent Click Through window with fade animation


This article is a follow up of the partly same named article, please start there if you come here first:

click to the begining

This time we extend our few lines of example with few lines of animation. This example is also use the Qt's framework capabilities like property animation and state machine.


One line switch


While I'm not paid by lines of code I'm always try to be simple and short.

The task is that we get an index and we need to know that this index is within a specific selection.

bool isInList(int index)
    bool result = false;
    switch (index)
    case 3 :
    case 5 :
    case 7 : result = true; break;

    return result;

Nice but to looooong...

This is simpler a bit ;)

bool isInList(int index)
    return std::set<int>{3,5,7}.count(index);

thanks for visiting.


Our company founded in 2010 to create commercial application based on customer needs.

These developments contributed own libraries and tools, the first of which a serialization micro framework is released.

We also add new articles in every week with code examples, tutorials which could helps software developers work, and promote better applications to deploy.

title link

C++ serialization tool - simply parse your current declarations and generate code within a few click for complex data structures serialization (supports: fundamental types, STL containers and tuple, smart pointers)

Click here to learn more.

Articles, code examples, tutorials Articles


Company introduction - software developments
Main entity of page: 
C++, example, Serialize, tutorial
Date modified: 
Sunday, January 29, 2017 - 23:30
Date published: 
Mega-Siraj Bt

Range-based loop, STL algorithms


When range-loop came into picture, I've started using it as soon as I could. As a programmer I'm looking for the simplest solution, which covers the problem, do the test and deploy. Let then the Computer do the dirty work! I'm its master! ;)

A person always looking for a better solution. A programmer is looking for a more simpler one, because over time, the code will be a subject of a rewrite or refactor (I still hear the screaming of managers, caused by these words ;)

Next is a source code for a range-loop method and an STL algorithm. They do the same thing, but looks a bit different. (We can also look at the code of those STL templates, and we'll find those for's ;)

This is a simple example, which not based on any real life story:

[code]#include <QString>

struct MyStruct
MyStruct(int id, QString text)
    : _id(id)
    , _text(text)

int _id;
QString _text;

At this point we have a struct declaration, which will plays as a key-value container on later. (Why is it key-value container then? that would be too simple ;)

Time to use our declaration, and set up some goals:

[code]#include <QList>

int main(int argc, char *argv[])
    // key-value pairs
    QList<MyStruct> _myNumbers = {MyStruct("0", "null"),};
    // request
    QList<int> _requests = {3, 5, 8};

    // result
    QList<QString> _result;

    // this is the place of solution code
    return 0;

The task is the following. Lookup each number from _requests within _myNumbers, and append a copy of the corresponding MyStruct's _text value to _results. (You are right! this job do not need a computer! this can be solved on a squared paper. believe me, there are simpler things are in this world which already programmed by big-BIG companies. :)

I'll first create a range-loop solution:

[code]for (auto& item : _requests)
    for (auto& elem : _myNumbers)
        if (elem._id == item)

Next the same goal, but simpler! :D

[code]_result = std::accumulate(_requests.begin(), _requests.end(), QList<QString>{}, [this](auto& a, int item){
    auto it = std::find_if(_myNumbers.begin(), _myNumbers.end(), [item](auto& elem){
        return elem.id == item;

    if (it == this->_detail.end())
        a.append(QString("No number like this one: %1").arg(item));

    return a;

Most of the range-loops could be replaced by with STL algorithms. Why is it good for? (for? I mean why is it good to use STL? ;)


  • The code will be more clear to others. The STL algorithms operations are obvious. Any container manipulation could be feasible.
  • Simpler to maintain. As we check this code parts, we surely know what the original author wants to do. Many for-loops could not be simple to understand
  • Easier bug fix. We could trust in STL code, which helps us reduce the error opportunities. (I know, we don't trust in STL at all! Just in ourselves! :)


I hope this article helps, and leads to refactor! (oh nooo, those screaming voices again... :)



Topmost semi transparent Click Through window


While I was learned at college, my UI design was very simple. All questions into one page - OK | CANCEL. One of my friend said that then, that this type of GUI design is close to the edge, the edge of terrible. I've redesigned the UI, to a 'wizard like' GUI.

Now, a few years ( decades :) later, User eXperience came into picture. I think the part of UX could be the application appearance. This step leads to animated and more pleasant UIs.

Current article is just a simple semi transparent window, which could show warnings, information and other messages, when we do not want user interaction, and we definitely do not want os annoying sound and messagebox combo!



QSettings vs. XML parser


This article is a comparison between QSettings and an XML format serialization.

The goal is to save/restore application settings. Based on a Qt linked application, QSettings is a very handful solution.

Small example,

Create our object:

[code]#include <QSettings>
QSettings* _settings = nullptr;

_settings = new QSettings(PATH_TO_YOUR + "/app.ini", QSettings::IniFormat);[/code]

// delete object

delete _settings; _settings = nullptr;[/code]

Adding a key/value:

[code]QString key;
QVariant value;

_settings->setValue(key, value);[/code]

Retrieve it as a QVariant:

[code]QVariant result = _settings->value(key/*, Default Value*/);[/code]

With these few lines of code, we could create quite as many settings keys with quite different types as QVariant gives us. (Fundamental types and class values)

My experience is the following:


  • everything goes through QVariant
  • simple, easy to use
  • platform independent

XML serialization/deserialization

  • key typo's are out of question,
  • more complex data structures
  • fast save/reload
  • platform independent
  • 3rd party tools can read/write output (which could be a disadvantage ;)

Let's create a simple example structure for an XML serialization:


struct SettingsUI

QString _windowsPos;
QStringList _openedWindows;
QRect _windowRect;


struct SettingsDB

unsigned _dbType;
int _dbPort;
QString _dbSchema;

struct SettingsMain

SettingsUI _ui;
SettingsDB _db;

 Using of one or another is mainly based on your use case. I hope this article helped you a bit.


Thanks for visiting.

The Q's are part of the Qt framework, all right reserved for Qt Company

Gepard ORM (GORM) serialization / deserialization

This article describes GORM version 1.4.0 capabilities.


Following is a typical collections of C++ fundamental types, STL containers and smart pointers.

[code]#include <types, STL, Qt, smart pointers>

class MySerializationBase final


    // Fundamentals
    bool        _bool1= false;
    int         _num1 = 0;
    uint32_t    _num2 = 0;
    uint64_t    _num3 = 0;
    long        _num4 = 0;
    long long   _num5 = 0;
    float       _num6 = 0;
    double      _num7 = 0;
    std::string _text1;
    QString     _text2;
    QDate       _date1;
    QTime       _time1;
    QDateTime   _datetime1;
    // Containers
    std::vector<int>    _contNum1;
    std::list<int>      _contNum2;
    std::set<int>       _contNum3;
    std::map<int, int>  _contNum4;
    std::tuple<int, int, std::string> _contNum5;
    QVector<int>        _contNum6;
    QList<int>          _contNum7;
    QSet<int>           _contNum8;
    QMap<int, int>      _contNum9;
    // Smart pointers
    std::shared_ptr<int> _smart1;
    std::auto_ptr<int>   _smart2;
    std::unique_ptr<int> _smart3;
    QSharedPointer<int>  _smart4;
    // User objects
    MySerializationChild                _link1;
    MySerializationChild*               _link2 = nullptr;
    std::vector<MySerializationChild>   _link3;
    std::vector<MySerializationChild*>  _link4;
    QList<MySerializationChild>         _link5;
    QList<MySerializationChild*>        _link6;
    std::vector<std::shared_ptr<MySerializationChild>> _link7;

Within this class is a reference to MySerializationChild class, which is mainly a HEAP oriented class with a lot of raw pointers.

[code]class MySerializationChild final


   // Fundamentals as pointers
   bool* _bool1 = nullptr;
   int* _num1 = nullptr;
   uint32_t* _num2 = nullptr;
   uint64_t* _num3 = nullptr;
   long* _num4 = nullptr;
   long long* _num5 = nullptr;
   float* _num6 = nullptr;
   double* _num7 = nullptr;
   std::string* _text1 = nullptr;
   QString* _text2 = nullptr;
   // TODO char* _text3;
   QDate* _date1 = nullptr;
   QTime* _time1 = nullptr;
   QDateTime* _datetime1 = nullptr;

The goal is to generate a code which creates an XML output and of course, on the other hand it loads that file and produce our object files.

Now, to save time, electricity, keyboard abrasion please download this Tutorial Skeleton: Click here.

Step-by-step tutorial with Gepard ORM,

  1. Open Gepard ORM, click on New / Load existing
  2. Create GORM project by Qt's project file
  3. For parse Qt dependent classes, you need to add some include folder
  4. Add myserializationbase.h and myserializationchild.h to Source files
  5. Click Serialization/Deserialization, select XML serialization format
  6. Click >>
  7. Click on structs/class fields to be confident in compile success
  8. Click Save, Click Create output
  9. Back to Qr Creator, compile tutorial and run ;)

That's should done.

The following files now created in generated_gorm folder:

  • gorm_myserializationbase.cpp
  • gorm_myserializationchild.cpp

Examine the source code, modify and use it on your will.


Thanks for using.