Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QRunnable unavailable dynamically allocated member variables

QRunnable unavailable dynamically allocated member variables

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 348 Views
  • 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.
  • R Offline
    R Offline
    RBLL
    wrote on last edited by
    #1

    Hi,

    I'm running into a weird behavior when dispatching the run() function of a class that inherits from QRunnable. The class in question has 2 member variables that are dynamically allocated in its constructor:

    float *mBufferX = new float[mBufferXSize.toInt()];
    float *mBufferY = new float[mBufferYSize.toInt()];
    

    Now, whenever the run() function is invoked, these 2 variables are NULL. However, the object exist and thus its constructor was called. How is it that these variables are NULL?

    Thank you very much!

    kshegunovK 1 Reply Last reply
    0
    • R RBLL

      Hi,

      I'm running into a weird behavior when dispatching the run() function of a class that inherits from QRunnable. The class in question has 2 member variables that are dynamically allocated in its constructor:

      float *mBufferX = new float[mBufferXSize.toInt()];
      float *mBufferY = new float[mBufferYSize.toInt()];
      

      Now, whenever the run() function is invoked, these 2 variables are NULL. However, the object exist and thus its constructor was called. How is it that these variables are NULL?

      Thank you very much!

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

      Assuming you posted exactly what you wrote in your constructor, you shadow the members with the local variables.
      https://en.wikipedia.org/wiki/Variable_shadowing#C++

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      5
      • R Offline
        R Offline
        RBLL
        wrote on last edited by
        #3

        Wow. How did I miss that...

        Well that should solve it. Thanks!

        1 Reply Last reply
        1

        • Login

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