Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crash with QMap as an argument
Forum Updated to NodeBB v4.3 + New Features

Crash with QMap as an argument

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 359 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on last edited by
    #1

    Hi, I’ve a problem with QMap as an argument passed to a class.
    I’ve 2 classes (MainWindow and ProcessData).
    In MainWindow.h I define the QMap as follow:

    QMap<uint16_t, QString> *m;
    

    In MainWindow constructor I fill my QMap with:

    m = new QMap<uint16_t, QString>;
    m->insert(0, “String0”);
    m->insert(1, “String1”);
    m->nsert(2, “String2”);
    m->insert(3, “String3”);
    

    Using “m” in MainWindow there isn’t a problem.

    The problem is when I give this QMap (m) to constructor of class ProcessData:
    In header, I declare the constructor as follow:

    ProcessData(QWidget *parent, QMap<uint16_t, QString> *LangMsg);
    

    and QMap:

    QMap<uint16_t, QString> *p;
    

    In .cpp file o class, the constructor is defined:

    ProcessData::ProcessData(QWidget *parent, QMap<uint16_t, QString> *LangMsg) : QWidget(parent)
    {
         p = LangMsg;
    }
    

    If I use “p” to extract string in any widget or object (for example QString s = p->value(0)) I haven’t a problem, but the program crash to this line:

    ParamTable->setHorizontalHeaderLabels(QStringList() << p->value(0) << p->value(1) << p->value(2) << p->value(3));
    

    If I declare and fill a fake *QMap p in class ProcessData(), there isn't a problem.
    I don’t understand why!
    Can you help me?
    Thanks.

    JonBJ 1 Reply Last reply
    0
    • S Stefanoxjx

      Hi, I’ve a problem with QMap as an argument passed to a class.
      I’ve 2 classes (MainWindow and ProcessData).
      In MainWindow.h I define the QMap as follow:

      QMap<uint16_t, QString> *m;
      

      In MainWindow constructor I fill my QMap with:

      m = new QMap<uint16_t, QString>;
      m->insert(0, “String0”);
      m->insert(1, “String1”);
      m->nsert(2, “String2”);
      m->insert(3, “String3”);
      

      Using “m” in MainWindow there isn’t a problem.

      The problem is when I give this QMap (m) to constructor of class ProcessData:
      In header, I declare the constructor as follow:

      ProcessData(QWidget *parent, QMap<uint16_t, QString> *LangMsg);
      

      and QMap:

      QMap<uint16_t, QString> *p;
      

      In .cpp file o class, the constructor is defined:

      ProcessData::ProcessData(QWidget *parent, QMap<uint16_t, QString> *LangMsg) : QWidget(parent)
      {
           p = LangMsg;
      }
      

      If I use “p” to extract string in any widget or object (for example QString s = p->value(0)) I haven’t a problem, but the program crash to this line:

      ParamTable->setHorizontalHeaderLabels(QStringList() << p->value(0) << p->value(1) << p->value(2) << p->value(3));
      

      If I declare and fill a fake *QMap p in class ProcessData(), there isn't a problem.
      I don’t understand why!
      Can you help me?
      Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Stefanoxjx said in Crash with QMap as an argument:

      but the program crash to this line:

      Please start with a Q_ASSERT(p)! Just in case.... You haven't even shown us your call to ProcessData().

      Nor, for that matter, your declaration of p. Which I sort of assume is a member variable? Recently people have been declaring member variables and then "shadowing" them with local variables using the same name, and wondering why they don't have the value of the member variable --- you're not in that situation are you?

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by Stefanoxjx
        #3

        Excuse me, I'm a stupid.
        In reality, the critical code line is called in another class :(
        Sorry.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved