Saturday, November 29, 2014

.Net 4.5 Async Await for a more responsive design

Writing this so I'll remember the details. There is a good resource on the Await and Async keywords in MSDN:

The key thing is that the execution is released back to the event loop until the async method is executed and completed. So there is no blocking of the event loop causing rendering problems in the GUI.

There is a lot of arrows in the sample in MSDN but the summary is that code will go back and resume executing the "continuation" after the async method has completed. This is great for long-running processes like downloading resources.

Saturday, November 22, 2014

Installing the Android Studio Beta

Google is moving to new IDE, Android Studio. it's only in Beta right now but when released it will be the preferred IDE and you will need to merge from Eclipse.

You have to install the java development kit 6 (JDK 6) the 32-bit and the 64-bit version, it that can be found here:

Installer for the Android Studio can be downloaded here

After installing the Android studio you have to add the JDK JAVA_HOME Environment variable setting if the installer script failed to do so, follow the instructions on the site. (the path should be to 32-bit or 64-bit depending on if studio.exe or studio64.exe will be used)

Also install the Android SDK, by downloading "Get the SDK for an existing IDE" Start the SDK Manager and download according to the instructions on the web site.

Start the Studio.exe in the Android Studio unzipped folder. Set the path to the Android SDK by clicking configure | project setting | project platform and setting the path.

Now you will be able to start a New project... By creating a project you start the IDE:

Found a tutorial that describe the Android Studio here:

The UX when installing the Android Studio is really bad, hopefully it will be a lot easier to install with all the dependencies when released.

Sunday, November 02, 2014

Compiling Qt code gave: multiple definition of ...

Got an error when compiling our code:

In Windows 7 and visual studio, I at first did not notice the problem, but it was giving a warning:
LNK4042: object specified more than once; extras ignored

In Linux and gcc it gave an error, so I could not compile the code:
multiple definition of `<constructor of class>'
collect2: ld returned 1 exit status

I took som time to figure it out, but turned out to be a bad merge in subversion, 
the *.pro file had the same class twice in

HEADERS += \ Class1.h /
SOURCES += \ Class1.cpp /

Rremoving the second time the class name where entered in the *.pro file solved the problem. See 

Friday, October 03, 2014

Been to a lunch seminar about Internet of Things

Went to Sogeti Internet of Things seminar on Wednesday lunch.
I made some notes:

Presenter was: @dagpetersson  

  • Electric IMP. Computer, WiFi, inputs for sensors. Very small.
  • iBecon. Localication, triangulation, water resistant.
  • LightBlue Bean. Test card, Temperature sensor, Accelerometer, iBecon. In and output.

IBM MessageSight, uses MQTT protocol. Can support up to 1 miljon devices.

We where also able to test Google glass, very interesting experience.  

Thursday, October 02, 2014

Qt and collect2 ld returned exit status 1

Got this error when building a unit test project:
collect2 ld returned exit status 1

The linker complained on my newly added class in the implementation project.

It took a while to figure it out, but the problem was that the old *.so file was left in Build folder when I tried to compile the lib file that was used by the unit test project.

The solution to the problem was to remove all files in the implementation project build folder. Followed by a rebuild of the implementation project and unit tests project could be built without any linker errors.

Sunday, September 21, 2014

Use Pomodoro Technique and instrumental music to get into the zone quickly

Was listening to Mark Seeman on .Net Rocks, talking about Getting into the zone.

Got some good advice's, Instrumental music tends to be better to listen to than lyrics or someone is talking when trying to get "into the zone" or flow.
I usually had a podcast or a radio station on while working. But I get it now, listening and processing when someone is talking and in the same time as I'm working with my brain is reducing the mental performance. After changing to classical or instrumental music in my playlist at work, I can feel that it's faster to get into coding quicker when interrupted.

I also picked up the Pomodoro technique mentioned in the show, after reading up on the technique developed by Francesco Cirillo and setting a timer on 25 minutes when working and 5 minutes of rest between every "pomodoro"/work session, I can say it works for me, getting more done every day.

Saturday, September 06, 2014

Solved: error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

Added two classes A and B both inheriting QObject.

#include <QObject>
#include "b.h"

class A : public QObject
    explicit A(QObject *parent = 0);

    QList<B> doStuff();


public slots:


#include <QObject>

class B : public QObject
    explicit B(QObject *parent = 0);


public slots:


But when adding implementation for A:

QList<GUIContainer> A::doStuff()
    QList<B> list;
    return list;


The compiler started complaining:
error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

It complains because:
"The values stored in the various containers can be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator."

Solved the error by changing the QList to be a list of QSharedPointer:
QList<QSharedPointer<B> > doStuff();

Sunday, August 31, 2014

How to find out if a shared library has Debug symbols

We had some problems with debugging on a remote system and did some searching on the Internet to find out how to ensure that the library indeed has debug information. 

This is the command that can be used:
objdump --syms ... | grep debug

Tuesday, August 26, 2014

Solved: Failed to start program. Path or permissions wrong?

Got this error in Qt: "Failed to start program. Path or permissions wrong?" after adding a new drive in our linux developer image in VM-Ware and moving our trunk to it. According to a lot of resources on the Internet the cause should be that the user don't have execute permission. But the user did and there were no difference when using root.

Found out that it was possible to check if mount was set to: noexec by using mount command and it was noexec although according to the GUI in mountmanager it was exec.

Found out that this issue could be solved by doing a remount:
sudo mount -o remount,exec /tmp

After the remount the error disappeared.

Thursday, August 21, 2014

SIGSEGV horror in the Qt project.

Had some problems in our project the application kept crashing with SIGSEGV error. We did not get a chance to catch the problem in the debugger making it hard to find. Found a neat trick on the internet, it's possible to add a handler for signals that catch the SIGSEGV and can print the stacktrace:

#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

void handler(int sig) {
  void *array[10];
  size_t size;

  // get void*'s for all entries on the stack
  size = backtrace(array, 10);

  // print out all the frames to stderr
  fprintf(stderr, "Error: signal %d:\n", sig);
  backtrace_symbols_fd(array, size, STDERR_FILENO);

void baz() {
 int *foo = (int*)-1; // make a bad pointer
  printf("%d\n", *foo);       // causes segfault

void bar() { baz(); }
void foo() { bar(); }

int main(int argc, char **argv) {
  signal(SIGSEGV, handler);   // install our handler
  foo(); // this will call foo, bar, and baz.  baz segfaults.

It's also possible to catch other signals:

Saturday, August 09, 2014

Qt connect is complaining that it can't find slot in super class when connecting sub class

Got an runtime error in the Qt application we are building, were connecting a signal with a slot, but when running the app we got this error message in the console:
Object::connect: No such slot mgccis::web::SuperClassWebservice::onReadyRead() in ServiceInterface\SubClassWebservice.cpp:37

The connect code in the SubClassWebservice looked like this:

connect(, SIGNAL(readyRead()), this, SLOT(onReadyRead()));

There was a slot in the subClassWebservice, took a google search session to find out the real problem, found this on Stackoverflow:

I've forgot to add the Q_OBJECT in the class declaration of the sub class.

Thursday, July 31, 2014

Change color on SVG item in Qt

This is a neat trick that can be good to know, found the solution in StackOverflow:

If you have for example an arrow that needs to be in different colors at different times in a Qt application, it's possible to change the color of an SVG item instead of adding several SVG items with different colors. 

QColor weightOutreachSupportArrowHorisontalColor = getWeightOutreachSupportArrowHorisontalColor();
yAxisIndicator_ = QSharedPointer<QGraphicsSvgItem>(new QGraphicsSvgItem(":/Icon/Icon/Arrow_x_30_30.svg",0));
QGraphicsColorizeEffect* weightOutreachSupportArrowHorisontalColorEffect = new QGraphicsColorizeEffect();


Monday, July 28, 2014

How to in Qt *.Pro-file disable: warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Got a compiler error when using sscanf in QT Creator:
warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

To make sure other warnings wont't disappear in the spam like messages caused by the c++ compiler, we wanted to disable the warning.

Tried to do add this at the top of the main.cpp file but got the same error:

Adding this in the *.PRO file did the trick:

#Removes: warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Wednesday, July 02, 2014

JSON-RPC with Fiddler

Needed to do a HTTP POST with a JSON RPC payload. Searched the web and there where a good explanation on StackOverflow explaining how to send  JSON string with fiddler:
Is it possible to make JSON requests using Fiddler's Request Builder?

Put the information together and adding the request in Raw and do Execute:

POST /StatusV1 HTTP/1.1
Host: localhost:8080
Content-Type: application/json; charset=utf-8
Content-Length: 81

{"method": "confirmRigModeKeySwitched", "params": ["correctPassword!"], "id": 99}

Worked as a charm!

Wednesday, June 25, 2014

error LNK2019: unresolved external symbol. Problem with linker in C++ is starting to give me gray hair.

Got this error message in the linker when I switched the project from statically linked to dynamically linked in the .Pro file:

StatusFacade.obj : error LNK2019: unresolved external symbol "private: enum mgccis::status::dto::StatusRigMode::Status __thiscall mgccis::status::StatusFacade::RigModeStatusToDto(enum mgccis::status::RigModeReply::Status)" (?RigModeStatusToDto@StatusFacade@status@mgccis@@AAE?AW4Status@StatusRigMode@dto@23@W44RigModeReply@23@@Z) referenced in function "public: class QString __thiscall mgccis::status::StatusFacade::getStatus(void)" (?getStatus@StatusFacade@status@mgccis@@QAE?AVQString@@XZ)

I just uncommented this row:
#CONFIG += staticlib #Nessesary only when running unit tests :(

The solution was easy, I had forgotten to set the class name on the methods in the cpp file, an honest mistake to do:
mgccis::status::dto::StatusOverloadTest::Status OverloadTestStatusToDto(mgccis::status::OverloadTestReply::Status overloadTestStatus)

Should be:
mgccis::status::dto::StatusOverloadTest::Status StatusFacade::OverloadTestStatusToDto(mgccis::status::OverloadTestReply::Status overloadTestStatus)

Strange that the linker did not complain when I statically linked the project. :)

Saturday, May 17, 2014

Solved: Qt Segmentation fault on MainWindow show() on line: inline void show() { setVisible(true); }

Writing this down so I'll remember in the future.

The application worked in Qt Creator in Windows, but in Linux we received Segmentation Fault when trying to run the application in the debugger.

Looking at the stacktrace only showed that it crashed in SetVisible on the main window.

0 __strlen_sse2 strlen.S 99 0x7e9520
1 XSetCommand /usr/lib/ 0xdbbb9f
2 XSetWMProperties /usr/lib/ 0xdc0601
3 QWidgetPrivate::create_sys(unsigned long, bool, bool) /opt/qt-4.8.4/lib/ 0x110db5e
4 QWidget::create(unsigned long, bool, bool) /opt/qt-4.8.4/lib/ 0x10bc73c
5 QWidget::setVisible(bool) /opt/qt-4.8.4/lib/ 0x10c20e5
6 QWidget::show qwidget.h 494 0x804fd0c
7 mgccis::shell::MainApplication::InitializeInterface mainapplication.cpp 29 0x804facc
8 main main.cpp 25 0x804efb0

It stopped on the line below, it made no sense all objects where initialized:

#ifndef Q_WS_WINCE
    inline void show() { setVisible(true); }
    void show();

After some googling of the subject I found this forum post that described a problem that can cause this error message, it's the signature on the MainApplication that can causes the problem:

But our solutionwas the opposite from the resolution in the forum post. We have our own builder class that gets the arguments from the main method and that passes the argument to the MainApplication, so in our case the solution was to send the argc parameter as value instead of a reference:

So the Change was from:
explicit MainApplication(int &argc, char* argv[]);

To this:
explicit MainApplication(int argc, char** argv);

After the change the application can be debugged in Windows and Linux and the error message made sense, we sent a reference to a temporary instance of the argc to the MainWindow that used when window is shown.

Saturday, April 26, 2014

Solved HP Administrator Tools disabled when trying to enable hardware virtualization for Windows phone emulator.

Got this message when trying to run the windows phone emulator on my new computer an hp folio 9470m:

Clicking on "More information" and you end up on this MSDN article:

Following the instruction I tried to log in as administrator in the BIOS but all Administrator Tools settings were disabled, could not find out why, the log in seemed to be ok with the credentials.

After searching the hp support forum I finally gave up and started to googling the problem, right a way I found this post on the hp support forum,

You have to log in as guest and set the BIOS administrator password to get the Administrator Tools enabled, really bad UX, why not prompt the user to set the administrator password the first time?

Wednesday, April 23, 2014

Error: Loading plugin error: Cannot load library /usr/local/SomeLib/ (/usr/local/SomeLib/ undefined symbol: _ZN18SomePluginModuleD1Ev)

Got this annoying error in QPluginLoader when I deployed and tried to run the application. It took a while before i realized what my mistake was.

I accidentally missed to add a implementation for the destructor and that caused the error message, found this forum post that got me in the right direction:

.h with destructor:

.cpp did not have:
   //clean up...

Friday, March 28, 2014

Sogeti Visual Studio 2013 ALM Roadshow2014, Örnsköldsvik

I went to Sogeti Visual Studio 2013 ALM Roadshow2014, Örnsköldsvik today. Interesting to hear what's new in Visual Studio 2013. 
Here is my notes from today:

Application Insight

Tool for collecting data on apps performance, crash, environment, etc.


  • Synchronize settings if you login using live account.
  • Scrollbar that gives meta information about the code.
  • Auto history, keeps track of changes locally, makes it possible to make a diff against older versions. Automatically or by doing snapshots.
  • Peek, Inline navigation between sourcecode files. keeps the code/context during navigating/peeking other files.
  • Code Map (VS Ultimate only), Visualizing the code blocks and how they are related. Also when debugging. (Can be opened in VS Premium)
  • Code Lens (VS Ultimate only), meta data inline in code. Test status, testing, bugs, workitem, code reviews, maintainability etc.
  • Team explorer, some tabs can be made floating and be docked  in other areas in VS.

Agile project management

  • Features can be added on a higher level (New in Team Foundation Server TFS 2013)
  • Easy prioriting items
  • Scrum board, easy to move items.

Microsoft Test Manager

  • Create test plan, connected to sprint.
  • Easy to create test cases
  • Can take a test drive of the product and create test case from the test drive.
  • Test professional (Tester or project manager)
  • VS Premium or Ultimate if developers what the test tools.
  • Using the web tools requires license as above.
  • UI test case using C# can be created from tests.
  • Possible to pause and resume test cases.

Release management

InRelease got bought by Microsoft and was integrated into TFS.
  • Free to use to keep track of releases.
  • But automatic deployment requires license for deployment agent (One deployment agent per VS Ultimate license).

Central, Distributed Versioning

  • Check-out Check-in (TFS 2010)
  • Edit Commit (TFS2012, CVS, Suversion)
  • Comit Push Pull (TFS 2013, GIT)

Friday, February 14, 2014

Solved: error: no match for call to '(QString) (QString&)' when emitting signal in Qt

I had an annoyning error message:
error: no match for call to '(QString) (QString&)'
when compiling my qt application.

Took some time before I found what was wrong, the code looked like this:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
    value_ = newValue;
    emit newValue(value_);

The error is that the signal name is the same as the variable:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
    value_ = newValue;
    emit newValue(value_);

So the fix is easy, changed the signal name:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
    value_ = newValue;
    emit updateValue(value_);

Sunday, February 09, 2014

How to make your blogger blog a pinned site with live tiles in windows 8.1

By using you can create the metadata tags that needs to be added to your site.

1. Added the name and some color:

2. Added the blogs rss feed

3. For my blogger site it created:
&lt;meta name="application-name" content="MathiasWestin.Net"/&gt; &lt;meta name="msapplication-TileColor" content="#666666"/&gt; &lt;meta name="msapplication-notification" content="frequency=30;polling-uri=;id=1;polling-uri2=;id=2;polling-uri3=;id=3;polling-uri4=;id=4;polling-uri5=;id=5; cycle=1"/&gt;
 This was added to the blogger template by editing the HTML like described in

So I added the following directly under the title tag, notice the added if tags needed to work in blogger, not needed if it's your own site:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
    <meta content='MathiasWestin.Net' name='application-name'/>
<meta content='#666666' name='msapplication-TileColor'/>
<meta content='frequency=30;polling-uri=;id=1;polling-uri2=;id=2;polling-uri3=;id=3;polling-uri4=;id=4;polling-uri5=;id=5; cycle=1' name='msapplication-notification'/>
 In IE open the page, right click and choose favorites, click the pin to start button:

The site is now added to start and it's live tiles are updated from the blogs rss feed.

Saturday, January 11, 2014

Unit testing in Native C++ using Visual Studio 2013

Test driven development TDD is used in many languages. and can be used in c++ as well. The support for unit test in native C++ was added in VS2012 and I thought I'll write a short blog post on how to get started in VS2013. I'll be using VS 2013 Express for Desktop for this blog post.

I'll use a static library but it is possible to add test projects to EXE or DLL projects as well for more information on that see:

Start Visual Studio 2013:

Visual Studio 2013 for Desktop
We start by adding the projects that should be tested MathLibrary and add a test project MathLibraryTests.

Choose "Add project":
Add project from start page

Add project from FILE menu
In the Add Project dialog, change the project to be a Visual C++ win32 project and the Name to be MathLibrary:

New Project dialog

In the Win32 Application wizard choose Next:
Win32 Application Wizard - Step 1

 In the Next step choose Static Library:

 Choose finish and the solution and MathLibrary project is created:

Build the MathLibrary project. Note in the output windows that the MathLibrary.lib file ends up in the Debug folder that is in the Solution folder.

Create the Test project by right clicking the solution and choose New Project:

In the New Project dialog, choose a Visual C++ Native Unit Test project and give it the name MathLibraryTests:

Link the MathLibrary with the MathLibraryTests project, this is done with three steps in the MathLibraryTests projects Properties:

1. Add the MathLibrary.lib to the Additional Dependencies in the linker input settings:

2. Add the path to the MathLibrary.lib file in the Additional Library Directories in the linker general settings:

3. Add the include files path in the Include Directories  in the
VC++ Directories:

Rebuild the MathLibraryTests project, The output should say that the build was successful:

The projects are now in place and we can start testing the application functionality. The functionality in this case will take a string with numbers and calculate the sum of the numbers.
Add a new unit test CalculatorTests, Right click the test project and choose "Add new item":

In the Add Item dialog, choose Test C++ Unit Test Class and give it the name CalculatorTests:

Add a new test method by renaming TestMethod1 to CalculateSumWithEmptyStringArgumentReturnsZero:
            // TODO: Your test code here

Add the Arrange, Act, Assert AAA implementation in the test method:
            int expected = 0;
            Calculator calculator{};
            std::string strArgument{ "" };

            auto actual = calculator.CalculateSum(strArgument);

            Assert::AreEqual(expected,actual,L"Should return 0",LINE_INFO());


Run the test project:

Failed or in this case a compiler error = Red

The reson is simple we need to implement the class and metod in the MathLibrary.

Right click the MathLibrary project and choose Add class:

Name it Calculator:

Add a  method CalculateSum,
#pragma once


class Calculator
    int CalculateSum(std::string stringNumbers);

#include "stdafx.h"
#include "Calculator.h"



int Calculator::CalculateSum(std::string stringNumbers)
    return 0;

Include calculator.h in the CalculatorTests class.

Run the test:

Result passed = Green:

Refactor and clean the code = Refactor

Re run the unit test, so no errors have been added.

Continue by adding a new test...

Test Failed.

Add new functioanlity...

Test passed


Test passed...

Well that's not all there is to it, but it's a start. After a while you will see the need for initializing and clean up as well as Stub, Fake, Mock object. 

Saturday, January 04, 2014

Subversion integration in Microsoft Office

Having a lot of specifications in subversion can be a good way to handles changes, but having to jump to explorer to get a lock or check-in makes you loose focus on what your doing.

There is a great plugin to help you handle Office documents in Subversion. The plugin is called msofficesvn it's easy to install there is only a few files to copy and paste in the correct folders, follow the instructions here and you be fine.