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!