Tuesday, December 22, 2015

Reverse Iterators in Qt 5.6

Reverse iterators are among new features of Qt 5.6 release (Qt 5.6 beta was released last week). Now they are supported for all Qt sequential containers (QList, QLinkedList, QVector, QStack and QQueue).

If we look at C++ standard library and its sequence containers (array, vector, list, forward_list, deque) we will notice that these containers support both iterators (begin, end) and reverse iterators (rbegin, rend). Well, ok, except forward_list, special alternative to list when reverse iteration not needed.

Now we will solve a simple task like iterating a QList backwards with a new means available (similar to this http://stackoverflow.com/questions/16441447/iterating-over-a-qlist-backwards):
#include <QCoreApplication>
#include <iostream>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QList<int> list = {1, 2, 3, 4};
    QList<int>::const_reverse_iterator cIter;
    cIter = list.crbegin();
    while(cIter != list.crend()) {
      std::cout << *cIter << std::endl;
      ++cIter;
    }
    return a.exec();
}

Output from this program is: 4 3 2 1

QList::crbegin() points to the first item in the list in the reverse order. It returns const_reverse_iterator.

QList::crend() points to the last item in the list in the reverse order. It also returns const_reverse_iterator.

reverse_iterators and const_reverse_iterators are working well with auto C++11 keyword. Here is the example:

#include <QCoreApplication>
#include <QVector>
#include <iostream>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QVector<int> qVector = {1, 2, 3, 4, 5};
    for (auto it = qVector.rbegin(); it != qVector.rend(); ++it)
    {
        std::cout << *it << std::endl;
    }
    return a.exec();
}
As you may guess, the output from this simple program is: 5 4 3 2 1

Tuesday, September 8, 2015

QImageReader: how to use and what's new in Qt 5.5

QImageReader is a Qt class which is able to work with images of different formats located in files or devices (like sockets, ports, etc.).

List of supported formats can be received in such a way:
QList<QByteArray> imageFormats = QImageReader::supportedImageFormats();
Typically these image formats include jpg, png, tiff, bmp, svg and some others.
 
Let's take logo from our site and cut a piece from it using QImageReader:



Imagine we need only bottom part from this logo, here what we need to do:
QImageReader *imageReader = new QImageReader("logo.png");
int x = imageReader->size().width();
int y = imageReader->size().height()/3;
imageReader->setClipRect(QRect(0,2*y,x,y));
QImage image = imageReader->read();
QPixmap pixmap = QPixmap::fromImage(image);
pixmap.save("logo_cut.png");
Here is the output:



All the previous code worked in previous versions of Qt. What's new in Qt 5.5? Functions which are working with transformation metadata - usually they are extracted from EXIF.

void setAutoTransform(bool)
bool autoTransform() const
QImageIOHandler::Transformations transformation() const

These three functions are new in Qt 5.5.

Let's take a jpeg photo rotated for 90 degrees.

QImageReader *imageReader = new QImageReader("photo.jpg");
std::cout << imageReader->size().width() << " x ";
std::cout << imageReader->size().height();
QImageIOHandler::Transformations transformation = imageReader->transformation();
After executing this code transformation is equal to QImageIOHandler::TransformationRotate90.

Tuesday, August 18, 2015

Qt charts: available options

What possibilities do you have if you develop a Qt application (C++ or QML) and you need to insert a nice chart like pie chart or bar chart or something more complicated? Let's look at some of the options:

1) Of course, Qt Charts module - solution from Qt Company itself. It provides the most popular types of charts: bar chart, polar chart, pie chart, scatter scart, as well as many examples and themes. Significant drawback is that it is not included into open-source version of Qt. But if you have commercial license, it is free for you.

2) KD Chart - solution from KDAB, nice one, they have Gantt chart which can be useful as well as popular charts: bar chart, line chart, pie chart. You can simply integrate their charts into your Qt application by using KDChartWidget which is ready to use. Licensing model is GPL or commercial license, you choose.

3) Qwt - library for usage in programs with scientific or techical background mainly. Compatible with Qt 4 and Qt 5 both. It contains basic 2D plots such as scatter plot, histogram, scatter plot. Also provides scales, sliders, thermometers, etc. Works well with large number of points (thousands and hundreds of thousands of points). Qwt is distibuted under its own Qwt license which is basically LGPL (Lesser GPL) with some restrictions.

4) QCustomPlot - Qt C++ widget supporting 2D plots with possibility of export to PDF and image formats like JPG, PNG or BMP. It is licensed under GPL or you can buy commercial license. Besides basic plots it also supports statistical and financial plots.

5) QtiPlot - cross platform solution intended mainly for scientific work. Supports both 2D and 3D plots, has some advanced features like statistical analysis, curve fitting, image analysis tools. If you are downloading binaries, you will need commercial license but you can use GPL license if you compile source code yourself.

IMPORTANT UPDATE: since Qt 5.7 will be released previously commercial only Qt Charts will be available under LGPLv3 license for open source users. This should probably make Qt Charts more popular.

Friday, July 24, 2015

Qt future releases

Qt 5.5 released July 1, 2015 was declared by Qt Company as semi-annual release. Next release Qt 5.6 according to currently available release plan should be available in early December 2015. But all previous releases usually were delayed for several months, we will see how this plan will come true.

According to this Qt 5.6 will be long-term support release and will still support C++ 98 features. As for Qt 5.7 it will be something completely new, moving to new compilers (MS C++ 2012 and GCC 4.7 will be required at least for compilation) and certain C++11 features will be also required.

Thursday, July 23, 2015

C# 6: importing static members of type

On Github you can find a great doc on new features of C# 6 available now in Visual Studio 2015 released July 20 2015:

https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6

In C# 6 it is easy to import static members of type and usually this is illustrated from types of .NET Framework. But nothing prevents you to import static members of your own types.

How to do this? Imagine you developed some great and very useful library with any functionality wrapped into static classes and methods:
using static System.Math;
using System;

namespace MathLibrary
{
    static public class MathClass
    {
        static public double round(double a)
        {
            return Round(a, 2, MidpointRounding.AwayFromZero);
        }
    }
}
Of course, in real life it will have a lot of methods and they will be much more complex. But it is not important for us now. To use round() in a new C# 6 way we just need to do the following:
using static System.Console;
using static MathLibrary.MathClass;

class Program
{
    static void Main()
    {  
        WriteLine(round(5.555).ToString("0.00"));
        WriteLine(round(2.995).ToString("0.00"));
        WriteLine(round(3.223).ToString("0.00"));
    }
}
Target framework for this code can be any - from .NET Framework 2.0 to .NET Framework 4.6 since this specific code doesn't require anything specific. But it can't be compiled in Visual Studio 2013.

Wednesday, July 15, 2015

We released Wallpaper Updater 2.5

Currently we are testing and updating our programs for Windows 10, new OS from Microsoft which will be officially released in 2 weeks. Today we announce Wallpaper Updater 2.5, new version of our free wallpaper manager which is fully compatible with Windows 10 (as well as with Windows XP, Vista, 7, and 8).

Learn more about Wallpaper Updater 2.5 release here.

You are welcome to download our program here.

Please leave any comments on our site or blog, they are all very helpful to us.


Tuesday, July 14, 2015

.NET Framework version in Windows 10

What version of .NET Framework does Windows 10 contain by default?

According to MSDN

https://msdn.microsoft.com/en-us/library/hh925568.aspx

versions 4.5 and later should be determined by Release value of registry subkey

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full

In preview version of Windows 10 which is available today this value equals 393295. In MSDN we find that the latest value:

393273 - .NET Framework 4.6 RC

So probably the final build of Windows 10 will contain .NET Framework 4.6 but actual value of Release can change, will be equal or greater than 393295. 

.NET Framework 3.5 is not released by default with Windows 10 (as well as with Windows 8) but can be installed optionally without any problem.





Tuesday, March 31, 2015

Specifying Control Panel Icon with Inno Setup



Common problem while creating installers is bad image which Windows displays for your program in Control Panel:


If you are using Inno Setup for creating installer this problem can be solved by adding one line to [Setup] section:

[Setup]
UninstallDisplayIcon={app}\PathToYourExe.exe

Usually this is enough but if your exe contains multiple icons you can select which one you would like to use. See Inno Setup documentation for details.

 If you skip this line, Windows will choose the icon itself and usually it will be ugly icon which you can see on the screenshot.


Thursday, February 12, 2015

Dr Alex Blewitt "Swift Essentials" Review



Swift Essentials book http://bit.ly/SwE6701 written by Dr Alex Blewitt and published by Packt is a basic introduction to Swift, new programming language introduced by Apple for Mac OS and iOS. No prior knowledge of Swift or Objective-C is required for reading this book however it is useful to have some experience as Mac OS user. To run sample code written by Dr Alex Blewitt for Swift Essentials you need Mac OS 10.9 with Xcode installed.
Before Swift most code for Mac OS and iOS was written in Objective-C. Swift adds more modern runtime  and automatic memory management. 
Author starts his book with description of Swift interpreter which can be easily launched from Xcode tools. We are getting acquainted with Swift basics: literals, difference between variables and constants, two collection types (arrays and dictionaries), control flow, functions, running of simple scripts. After you've got familiar with command line interpreter Dr Alex Blewitt presents you a graphical interface called playground which allows to compile and execute code interactively. In the book he describes how to create playground, how to mix code and documentation within the playground, how to look at the state of executing program. 
Then Dr Alex Blewitt shows the reader how to create single view iOS application, how to create master-detail iOS application, how to work with storyboard application and create custom views.  The final target of the book is to build a fully functional iOS application which is repository browser working with GitHub API.
This book will be interesting for everyone who would like to get acquainted with Swift and start creating applications for Mac OS and especially iOS using Swift.