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. "this" is 0 in debuger
Forum Updated to NodeBB v4.3 + New Features

"this" is 0 in debuger

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 795 Views 3 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.
  • O Offline
    O Offline
    OpenGL
    wrote on last edited by
    #1

    I'm trying to find an issue in my code that is strange. Everything seems to work, but when I call a method (set_value) of an object of a custom class it crashes.
    The code looks like this (with a lot of code cut away)

    class MyClass : public QWidget 
    {
    private:
        QString m_name;
    }
    
    void MyClass::set_value(QString key, QString value)
    {
        qDebug()<<value;  // debug is added to this line
        qDebug()<<m_name;  // m_key is a member of the class. 
    

    In the console window in qtcreator I see the value "value" printed, but it crashes when it tries to print m_name.
    I can successfully add

     qDebug()<<m_name;
    

    in the constructor.

    When I try to debug, I add a breakpoint in set_value and it shows in the "Local and Expressions" window:
    this 0x0

    and that can't be good, can it?
    Any suggestions on where to start looking for the problem? It seems counter-intuitive to reach the set_value function if "this" would really be null.

    kshegunovK 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Can you show how you use the/a instance of MyClass ?
      Maybe you have an out of scope issues as otherwise it sounds odd.

      1 Reply Last reply
      3
      • O OpenGL

        I'm trying to find an issue in my code that is strange. Everything seems to work, but when I call a method (set_value) of an object of a custom class it crashes.
        The code looks like this (with a lot of code cut away)

        class MyClass : public QWidget 
        {
        private:
            QString m_name;
        }
        
        void MyClass::set_value(QString key, QString value)
        {
            qDebug()<<value;  // debug is added to this line
            qDebug()<<m_name;  // m_key is a member of the class. 
        

        In the console window in qtcreator I see the value "value" printed, but it crashes when it tries to print m_name.
        I can successfully add

         qDebug()<<m_name;
        

        in the constructor.

        When I try to debug, I add a breakpoint in set_value and it shows in the "Local and Expressions" window:
        this 0x0

        and that can't be good, can it?
        Any suggestions on where to start looking for the problem? It seems counter-intuitive to reach the set_value function if "this" would really be null.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @OpenGL said in "this" is 0 in debuger:

        and that can't be good, can it?

        It ain't.

        Any suggestions on where to start looking for the problem? It seems counter-intuitive to reach the set_value function if "this" would really be null.

        Where you call that function with a null pointer - i.e. use the call stack in the debugger and step out of set_value(). There's where you should look for the problem.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        4
        • O Offline
          O Offline
          OpenGL
          wrote on last edited by
          #4

          I found the issue. I was adding the MyClass objects to a Map with the wrong key.
          Hint: never use toInt() without verifying the conversion....

          1 Reply Last reply
          2

          • Login

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