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

Good cop/bad cop interview - 2nd phase

Welcome back,

If you may miss the first part, you can read it Good cop/bad cop interview - start.

Good cop - I'm sure you don't have that C++ labelled bullet in your leg! These codes were tricky but not for you!

Bad cop - Yes, because you do not figure it out without a compiler!

Good cop - That not true. I knew those.

Bad cop - Liar.

Good cop - Don't start to piss me of again Bad cop!

Bad cop - Stop lying!

After all, here we again. Our brave admissions are fight again, unsure the job applicant, discredit the company! This is the time to stop them and get back to some more tricky examples!

[code]#include <iostream>

int main()
unsigned c = 2004;
const int &d = c;
std::cout << "c value: " << c << std::endl;

c = 2012;

std::cout << "c value: " << c << std::endl;
std::cout << "d value: " << d << std::endl;

Bad cop - Ahm... the output?

The evil within is the unsigned int => ref int. This is only works when we declare our integer reference as const. This let happen an implicit conversion in the background from unsigned integer to signed integer. For this step there is a hidden memory allocation to hold the converted value of c for the reference of d. Passing method parameters as const references may do this trick (implicit conversion) behind.

Bad cop - But what we really love in C++ is the following: (Bad cop show some empathy and enthusiasm, but be sensible!)

[code]#include <iostream>

class Base
Base() {std::cout << "Base()\n";}
~Base() {std::cout << "~Base()\n";}
Base(const Base&) {std::cout << "CopyBase\n";}

class Derived : public Base
Derived() {std::cout << "Derived()\n";}
~Derived() {std::cout << "~Derived()\n";}
Derived(const Derived& other) {std::cout << "CopyDerived\n";}

Base* create(Base g)
return new Derived();

int main()
Derived d;

Base* g = d.create(Base());
delete g;

return 0;

Bad cop - what about an output?

Good cop - yes that would be nice!

(Thanks God, they agree on something for the first time! :)

This example tries to figure out that the applicant knows how virtual destructor works. (Or at least knows what could happen when it's missing?!) This example is good as the parameter static and dynamic type is clear. We have a variable d, which type is Derived. This variable created on the stack and freed when we run out of its scope. The ctor and dtor call is obvious - Base() -> Derived() when destroyed -> ~Derived() -> ~Base().

But we create a g variable where the static type is Base, but the dynamic type is Derived! That's okay, but when the destructor called by the delete, then only ~Base() gets called, because it's destructor is not virtual! There is no virtual table, so there's no chance to know where to go when destructing g.

(While our brave cops do not check this code with a compiler, they forget to ask about the Derived class copy construct missing explicit Base class initialization. ;)


We may continue... (With our experiences)

Good cop/bad cop interview - begin


Good cop - This article is about how good is C++!

Bad cop - Yeah! Because you do not understand it!

Good cop - Ahm... let see some really exciting examples of C++!

Bad cop - or, maybe, now we can see how miserable you are!

Good cop - What? No, no. This could be very useful code examples, which helps your everyday life!

Bad cop - or, you can feel yourself smarter than the job applicant! What a wonderful character you are! (no you are miserable)

Good cop - What? R U F4cking with me? I'll show you who is bad!

Bad cop - WAIT! That should be me?!?!?! Or????

We (I and one of my college) have interviewing job applicants for C++ positions. We mostly trying to plays the good/bad cop situation, but honestly, we mostly playing both on the good side (how cowards we are  :).

I will explain my personal experience about how it goes as a job applicant later, but first let's give a session to "Bad cop"!

Bad cop - Hi! We really glad to have you here! Our method of HR technic is a personal interview! So, let's just go through some simple C++ code examples! I'm sure with your experience you will easily figure out the answers!

Bad cop - Something really simple:

[code]#include <iostream>

void modify(int* number)
int b = 20;
number = &b;

int main(int argc, char* argv[])
int a = 10;
int* n = &a;

std::cout << *n << std::endl;

return 0;

Bad cop - what is the output? (Any other problems?)

  • Crash? Undefined behaviour? 5? 10?

Of course it will output 10. This code is a bit tricky, but clarify a simple step. Function parameters are copied (except reference). In this case within the scope of "void modify(int* number)" the integer pointer is copied. The parameter number is an integer pointer which's points to the same memory location as v, as long as we overwrite it at line 6. Bad cop likes when the job application wants to brake the hand of that person who writes this code. (This behaviour is not exclusion from the interview process ;)

Bad cop - I know you pass this! Let's see the next one:

[code]#include <iostream>

class MyClass
void foo()
std::cout << "This class is MyClass" << std::endl;
int id;

class Derived : public MyClass
void foo()
std::cout << "This is class Derived" << std::endl;

int main(int argc, char* argv[])
MyClass* my = nullptr;



return 0;

Bad cop - and the Question IS, what is tha f****ng output???? :D (Bad cop likes to raise the stress level a bit)

Bad cop - so, crash? Undefined behaviour? Maybe 10? (He is a real jerk sometimes, excuse us ;)

Calling a method on a nullptr? What happened under the hood?

As we know the memory layout, the MyClass implementation goes to the code segment. In this case, there aren't any use of tag members within void foo(), so there aren't any object call. There aren't any polymorphism, so there aren't any call to the virtual table, because it won't needed to exist.

And line 29? I hope you strive to break some hands caused by the C cast! This situation much more shitty, because it will be a static_cast<Derived*>(my), so after all we get that bullet in our leg, while it will be a call to Derived::foo() after all!


More bad cop and weird code examples for job applicants in the next article!

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!




title type link
Gepard ORM (GORM) serialization / deserialization Tutorial click to read
Range-based loop, STL algorithms Code example click to read
QSettings vs. XML Code example click to read
Transparent click through window Code example click to read
Transparent click through window with fade animation Code example click to read
Simple switch Code snippet click to read
RVO and move semantics ( C++11 ) Code example click to read
Good cop/bad cop interview - begin Code example, interview click to read
Good cop/bad cop interview - 2nd phase Code example, interview click to read


C++ articles, examples, tutorials
C++,articles,examples, tutorials
Date modified: 
Monday, January 2, 2017 - 00:30
Date published: 
Mega-Siraj Bt

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.