Friends,
I have code with the following structs (note the void pointer is there as there are other structs similar to KCKey it often references. Have not shown for brevity).
I place these arrays as Global Variables (I know not best practice, but lets go along with it for now). These global variables are declared as extern in one headers, and accessed in other source code.
The problem is in struct KCKey. When using the "keyprint" variable as const char *, it compiles, runs and works well. When using the "keyprint" variable as QString, I get a SEGFAULT with the following message: "the inferior stopped because it received a signal from the operating system. Signal name SIGSEV.
The code stops in "atomic_base.h".
Why does the code work with const char * , but not QString.
I don't believe this has to do with memory allocation because: 1) it crashes with ONE instance of global variable using QString, and 2) similar code runs well using std::string in an embedded microcontroller within tight memory constraints.
struct KeyCap{
int map;
int row;
int col;
int layer;
int keytype;
void * void_ptr;
};
struct KCKey{
int keycode;
QString keyprint;
};
As requested with additional code: example global header file:
Map_A.h
#ifndef MAP_A_H
#define MAP_A_H
#include <QString>
#include "structs.h"
extern KCMap Map_A;
extern KCLayer l_aDefault;
extern KCLayer l_aFN;
extern KCLayer l_aNUM;
extern KeyCap Map_A_Default[6][13];
extern KeyCap Map_A_FN[6][13];
extern KeyCap Map_A_NUM[6][13];
//~~~DEFAULT LAYER KEYS~~~~~~~~~~
extern KeyCap AD_00;
extern KeyCap AD_01;
extern KeyCap AD_02;
extern KeyCap AD_03;
Map_A.cpp
#include <QString>
#include "Map_A.h"
#include "keycodes.h"
#include "structs.h"
KCMap Map_A = {l_aDefault, l_aFN, l_aNUM};
KCLayer l_aDefault = {*Map_A_Default[0]};
KCLayer l_aFN = {*Map_A_FN[0]};
KCLayer l_aNUM = {*Map_A_NUM[0]};
KeyCap AD_00 = {zMap_A,0,0,1,no_key,&Key_None};
KeyCap AD_01 = {zMap_A,0,1,1,no_key,&Key_A};
KeyCap AD_02 = {zMap_A,0,2,1,no_key,&Key_B};
KeyCap AD_03 = {zMap_A,0,3,1,no_key,&Key_C};
KeyCap AD_04 = {zMap_A,0,4,1,no_key,&Key_D};
Keycodes.h
#include <QString>
#include "structs.h"
#include "keycodes.h"
KCKey Key_None = {0,""};
KCKey Key_A = {KEY_A,"A"};
KCKey Key_B = {KEY_B,"B"};
KCKey Key_C = {KEY_C,"C"};
KCKey Key_D = {KEY_D,"D"};
KCKey Key_E = {KEY_E,"E"};
KCKey Key_F = {KEY_F,"F"};
KCKey Key_G = {KEY_G,"G"};
KCKey Key_H = {KEY_H,"H"};
KCKey Key_I = {KEY_I,"I"};
KCKey Key_J = {KEY_J,"J"};
KCKey Key_K = {KEY_K,"K"};