Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QRunnable unavailable dynamically allocated member variables

    C++ Gurus
    2
    3
    133
    Loading More Posts
    • 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
      RBLL last edited by

      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!

      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @RBLL last edited by

        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 Reply Quote 5
        • R
          RBLL last edited by

          Wow. How did I miss that...

          Well that should solve it. Thanks!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post