Category Archives: Tutorials

How to develop GUI Application with PyQt (python Qt)

There are two main methods for developing GUI application with qt:
1) Adding all widgets in your code (your cpp or python code)
2) Creating qt UI files, adding widgets there and load everything into your application.

1)Adding all widgets in your code

Here is the snippet for adding all widgets and their slots in code:

2) Creating qt UI files, adding widgets there and load everything into your application

Now let’s do what we have done in the first method in a UI file and load it. First, create a text file and put the followings in it and save it as “mainwindow.ui”

Now call it in your python file like this:

The results should be the same as what you got in the first method.

Clang format and code beautifier for Qt Creator

Different developers use different styles with different IDE (i.e some people use space, some use tab) which may cause lots of change in your git repository. One solution to this is to use some standard code formatting and beautifier. clang is a great tool for this purpose and can be easily integrated with git hooks and IDE.
First, install it by:

now if you have a file like this:

after running the following:

now you can use it like:

Available styles are LLVM, Google, Chromium, Mozilla, WebKit.

You can config clang for Qt Creator:

go to Tools>Option then:

And then go to the Environment>keyboard and set your shortcut:

This is what I get after pressing shift+s:


Every thing you need to know to master git, Part 7, git branch

It quite often happens that a software product is on a git server and developers add new features to the product. To make the job easier, developers usually create branches beside the master branch (which is the default branch) and work on their branch and once the changes are confirmed and tested, they will be merged to the master branch. So let’s get started:

ok now let’s create two branches, one for developer1 and one for developer2,

let’s make some work on the first branches:

and some changes in the second branch:

now you should see this in git gui or if you type:

Now in the git gui, go to merge>local merge and choose b1, you will get the following error because of the merge conflict:

so call the following to solve the conflict:

choose C and save and then:


Every thing you need to know to master git, Part 6, git stash

Sometimes you have made some changes into your local copy and you don’t want to make a commit because your code doesn’t compile, but something came up and you should change your branch for instance and you will lose your local changes. In this situation, you can stash your changes and save your changes and change your branch for instance.

Let’s have a complete example:

now we make some change:

now let’s stash changes:

we can list and drop changes by:


Every thing you need to know to master git, Part 5, git cherry-pick

To illustrate what is cherry-pick let’s imagine  the following situation: you and another developer start working on project, you will both make some changes, but after a while the other developer find a bug in the code and you are interested in to only apply that hot-fix without taking other changes from another developer, in this situation you should do a cherry pick, so let’s do it:

and you continue with something like:

The other developer checks out the repository and will start working and make the second commit:

and in the third commit, he fixes the problem with A.txt so he would something like this:

And he may continue his work with another commit:

Now you are only interested in the third commit and you don’t want to add other files to your local copy so you have to cherry pick the third commit, so all you have to do is fetch all changes, find the corresponding SHA1 value for the third commit and apply the cherry pick.

And now the file A.txt in repose1 should be same as the file in repose2 while C.txt and D.txt are not added to repose1.




Every thing you need to know to master git, Part 4, git merge, git diff with GUI tools


Before following this post, make sure you have already set up everything from my other post regarding the configuration of git environment.


Diff command will allow you to compare two different commits, let’s set up a repository:

Now in the second repository, we make some changes:

now let’s back to the first repository and see the changes:

now you should see all the difference in meld:

Merge and conflict

now let’s merge all the changes. If you make some changes on dii=fferent files you will do fast-forward. That means you only incorporate new changes and everything is ok afterward. But if you made some changes on the same file in same lines then you have a merge conflict and you should do a three-way merge.

To show you the point lets make some changes in the first repository in the file A.txt.

now if you call git merge, you will get a merge conflict, to solve this call the following:

and you will get this in meld:

and this in kdiff:

|                MERGED               |

LOCAL: Your side of the conflict – ie, your branch (HEAD) that will contain the results of the merge
REMOTE: The remote side of the conflict – the branch you are merging into HEAD.
BASE: The common ancestor of both local and remote. useful for feeding into a three-way merge tool
MERGED: The result of the automatic merge.

go through the conflict and choose the side (A, B or C) and see the merged file in the window below and save and close.

Everything you need to know to master git, Part 3 (git checkout and git clean)

Cleaning up git environment and rollbacking local changes

Once you started working on your local copy you might mess everything and need to clean up or roll back changes for some file, you can use git checkout and git clean

to rollback changes for a particular file:

to rollback changes for the entire local copy while keeping added files:


if you just want to remove the file and directories that have been added but not staged:

Remove untracked directories in addition to untracked files.

Don’t actually remove anything, just show what would be done.

Show what would be done and clean files interactively. See “Interactive mode” for details.

Everything you need to know to master git, Part 2, git revert, reset amend

How to undo a commit in Git when no one has pulled your changes from the repository? git reset

git reset will do this job for you, it has two option, hard and soft,

git reset –hard/ –soft <SOME-COMMIT>

1)Hard: this option will reset the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

2)Soft: this option will leave the unstaged files in the working tree.


A Complete setup


some important note:

git add -A is equivalent to

Let’s continue our work:


The git reflog command records a chronological history of everything you have done in your local repository. Its full output might look like this:

C.txt and D.txt will remain (soft)

C.txt and D.txt will be deleted.

To see which files have been added and status:

Finally lets’ push changes by:


How to undo a push in Git when someone might have pulled your changes from the repository? git revert

If you’ve already pushed your changes and someone else pulled in those changes, you should not use git reset to undo changes, use git revert instead.


Let’s follow our work:


How to edit the git comment? git commit –amend -m “updated”

This will fix your most recent commit message



Pushing into the wrong branch

A very practical situation for the above command is pushing into the wrong branch,