Archive for the ‘C++11’ Tag

NetBeans and Qt5


After upgrading from NetBeans 8.0.1 and switching to Qt5 I noticed that the compiler C++ standard switch was set to c++0x and when setting the C++ standard to C++14 in the project settings the compiler standard switch is left out completely with the result that the compilation fails. I’m currently using the g++ 4.8 compiler, the documentation states that c++0x is deprecated and c++11 should be used instead and the switch for experimental C++14 support is c++1y.

Digging through the various make and project files showed the addition of -std=c++11 to QMAKE_CXXFLAGS was made only when the major version of Qt equalled 4. Oddly c++11 is added to a symbol called CONFIG if the major version is 5. These additions are found in qt-Release.pro and qt-Debug.pro project files. If the selected standard is set to C++14 the addition to CONFIG is missing. I haven’t been able to determine where the -std=c++0x comes from.

It’s clear that NetBeans 8.1 and earlier version don’t properly support Qt5. Switching back to Qt4 resulted in the correct standard switches been added for C++11 and C++14, the C++14 failed build failed because g++ 4.8 doesn’t recognise -std=c++14.

NetBeans can be used with Qt5 with the correct settings for the C++ standards. First set the standard to default:

Setting C++ standard to default

Setting C++ standard to default

Even if C++11 is be used this will suppress the addition of -std=c++0x. The required C++ standard option can be added using the custom definitions in the expert section of Qt project properties:

Custom definitions

Custom definitions

adding the required compiler switch for C++11:

Adding the C++ standard option

Adding the C++ standard option

The custom definition is truncated in the picture, in full it is:

equals(QT_MAJOR_VERSION, 5) { QMAKE_CXXFLAGS+="-std=c++11"}

The check for Qt 5 can be omitted if you don’t intend to swap between Qt4 and Qt5.

So the correct standards can be set when using Qt5 with NetBeans, experimental C++14 support in g++ 4.8 can also used by using c++1y instead. There are currently 3 g++ branches, the latest versions being 4.9, 5.3 and 6.1, these compilers accept -std=c++11 and -std=c++14, in addition 6.1 accepts -std=c++1z for the forthcoming C++17. The appropriate standard can be set depending on your compiler, if your using 6.1 then the custom definition can be deleted as the default standard id C++14.

In short if your using Qt5 with NetBeans always set the C++ compiler standard to default and specify the standard you want to use in Qt custom definitions.

Advertisements

Posted 9 June 2016 by element90 in Development, Linux

Tagged with , , , , ,

Migration to Qt5   Leave a comment


So far I’ve been using Qt 4.8 on both Linux and Windows 7. The compiler used on Windows 7 was Microsoft Visual Studio C++ version 10.0 which came with Visual Studio 2010 Express. The Microsoft compiler had poor support for C++11 features which meant I had to code my fractal software such that it would successfully compile on Linux and Windows.

Fed up with not being able to use C++11 fully on Windows led me to upgrade to Visual Studio 2015 Community. Since Windows 8, 8.1 and 10 have been released since I first released my software for Windows I went the whole hog and upgraded to Windows 10, upgraded to Qt5 built for 32-bit and Qt5 built for 64-bit using Visual Studio 2015 and upgraded QtCreator to version 4.0.0.

Over on Linux Mint the shift to Qt5 was easy, all I had to do was install the Qt5-default package:

Selecting Qt5

Selecting Qt5

If need be I can easily switch back to Qt4 by uninstalling Qt5-default and installing Qt4-default instead.

Building SaturnQt using Qt5 required just one change to its NetBeans project:

Select project properties

Select project properties


Add QtWidgets

Add QtWidgets

The location of Qt classes has been rearranged so QtWidgets is required for Qt5 but not for Qt4.

The project built without any problems and when SaturnQt was started some differences in appearance were evident, first the main window and the settings window for the Qt5 build:

Main window using Qt5

Main window using Qt5


Settings window using Qt5

Settings window using Qt5

and these are main and settings windows for the Qt4 build:

Main window using Qt4

Main window using Qt4


Settings window using Qt4

Settings window using Qt4

There are some obvious differences:

  • The window background colour is lighter using Qt5.
  • The height of the iterations box is the same as the zoom selection combobox using Qt5, they are not when using Qt4.
  • The list cursor is blue instead of green using Qt5.

There are other minor differences. In short Qt5 doesn’t match the MATE theme I’m currently using with Linux Mint. It should be possible to solve this issue and when I do I’ll post it on this blog.

Back to Windows. The project file for SaturnQt already had a check for Qt5 and automatically adds QtWidgets. QtCreator was then configured to use the 32-bit build of Qt 5.6 and to use the Visual Studio C++ version 14.0 compiler. The first build failed as std::max requires the inclusion of <algorithm> which is not required for Linux it has been added to the source code causing no issues for the Linux build. In addition there were a large number of warnings, I’ll cover these when I compare g++, clang++ and the Microsoft compiler in an other post.

Running the project successfully started SaturnQt on Windows 10:

Main window on Windows 10

Main window on Windows 10


Settings window on Windows 10.

Settings window on Windows 10.

I haven’t yet built a 64-bit version for Windows 10 as I need 64-bit libraries for MPIR and MPFR (for multi-precision arithmetic) and the QtCreator project file needs to be modified to support 64-bit builds. There will be a post on building 64-bit versions of my software for Windows in due course.

Qt5 versions of my software will not be available until I’ve finished the next versions and sorted out the release packages which will be affected by the transition to Qt5.

I Knew it was too easy – part 2   Leave a comment


At the end of the the post “I knew it was too easy” I mentioned that easiest method to get the parameter data out of Saturn seed files was to read the file directly and extract the keys and their values from the tEXt chunks. It was simple to implement and so I continued with development of version 4.0.0 of Saturn, today I noticed that when loading a seed file the wrong colour map was used, a colour map called Greyscale was unexpectedly used. The Greyscale colour map is a simple “auto” generated colour map which is defined as a single cycle sine wave for the red, green and blue components, the expected colour map was also an auto generated colour map. The problem turns out to be that the keys, “colour0”, “colour1” and “colour2” and their data were not extracted from the seed file, so that when the data was requested empty strings were returned and the default values were used instead which corresponds to the Greyscale colour map.

So why weren’t the keys and their data extracted from the seed file? Using a Linux utility called pngmeta all the keys and their data can be printed for any PNG file and that showed that the seed file did indeed contain the keys and their data for the “auto” generated colour map. But what exactly is in the file? Using a hex editor the answer is that Qt had embedded the colour map data using zTXt chunks and not tEXt chunks. The difference between zTXt and tEXt is that zTXt compresses the data but not the key, the data for the “colour0” was 46 characters, the length of the compressed data in the zEXt chunk is 120 bytes, the length of the data for “colour1” and “colour2” are 48 bytes each and the compressed size is again 120 bytes. This makes no sense, the compressed data is larger than the data to be compressed!

PNG files only support zlib compression (as far as I know). I initially looked for documentation on zlib which of course would have a C interface. Saturn is written in C++ so some method of accessing zlib’s functionality from C++ would be preferred, my initial thought was “Does Boost handle zlib decompression?”, after a bit of searching the answer is, “Yes, it does”.

I loaded the compressed data into a std::vector and then passed it to a utility routine to convert it into std::string:

std::string uncompress(std::vector<char>& buffer)
{
    std::string str;
    io::filtering_ostream os;
    os.push(io::zlib_decompressor());
    os.push(io::back_inserter(str));
    int size = buffer.size();
    for (int i = 0; i < size; i++)
    {
        os.put(buffer[i]);
    }
    // the above loop could be replaced using
    //
    // os.write(reinterpret_cast<char*>(&buffer[0]), buffer.size());
    //
    // or
    //
    // os.write(buffer.data(), buffet.size()); // C++11
    //
    return str;
}

A fragment of code on its own, usually results in questions such as “Where is io defined?” and “What headers should I include?”, so here are the missing pieces required to compile the code:

#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>

namespace io = boost::iostreams;

At one time the different path delimiters used on Windows and Unix/Linux meant that different include statements had be used and were selected by condition compilation, fortunately the Microsoft C++ compiler I use happily accepts Unix style delimiters.

I’ve used some C++11 features in my code, I would use more except that compiler support is not yet complete and as I release Saturn and Titan for Linux and Windows I have to take account of the compiler that has the least support and that is Microsoft’s. The sooner better C++11 support is more widespread the better as much cleaner code can written.

So now all the embedded data can be extracted from Saturn seed files, so the next release is one step closer.

Posted 8 May 2013 by element90 in Programming, Software

Tagged with , , , ,

%d bloggers like this: