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. ((TexoDemo*)prm) meaning what?
Forum Updated to NodeBB v4.3 + New Features

((TexoDemo*)prm) meaning what?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.3k 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.
  • Z Offline
    Z Offline
    zxw2006063
    wrote on last edited by
    #1

    Hi,

    I am trying to understand one project written by others. Here are a few lines which I have to difficult to understand.

    int TexoDemo::onData(void* prm, unsigned char* data, int)
    {
    // go past the frame tag
    ((TexoDemo*)prm)->wDisplay->display(((char*)data) + 4);
    ((TexoDemo*)prm)->iDisplay->setImgData(((char*)data) + 4);
    return 1;
    }

    Where TexoDemo is a class and onData is a function defined inside this class. wDisplay is a UI widget (promoted one).

    The bit that I do not understand is the grammar ((TexoDemo*)prm). What is this supposed to mean? I know this might be a C++ basic but I just don't know where to look it up. I don't even know how to search for this C++ problem.

    I would appreciate the help from anyone. Thank you.

    Regards
    Xiaowei.

    K 1 Reply Last reply
    0
    • Z zxw2006063

      Hi,

      I am trying to understand one project written by others. Here are a few lines which I have to difficult to understand.

      int TexoDemo::onData(void* prm, unsigned char* data, int)
      {
      // go past the frame tag
      ((TexoDemo*)prm)->wDisplay->display(((char*)data) + 4);
      ((TexoDemo*)prm)->iDisplay->setImgData(((char*)data) + 4);
      return 1;
      }

      Where TexoDemo is a class and onData is a function defined inside this class. wDisplay is a UI widget (promoted one).

      The bit that I do not understand is the grammar ((TexoDemo*)prm). What is this supposed to mean? I know this might be a C++ basic but I just don't know where to look it up. I don't even know how to search for this C++ problem.

      I would appreciate the help from anyone. Thank you.

      Regards
      Xiaowei.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @zxw2006063

      That is pointer casting. Like in here

      Or also in here
      it is better to use for instance dynamic_cast or one of the others

      Vote the answer(s) that helped you to solve your issue(s)

      Z 1 Reply Last reply
      1
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        prm is the void argument for your onData function. wDsiplay must be the member variable inside the class TexoDemo. To access this variable you need to typecast the prm to TexoDemo type. If you don't typecast, wDisplay will not be able to access.
        display must be a function of wDisplay.

        Hope that clarifies.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        Z 1 Reply Last reply
        5
        • K koahnig

          @zxw2006063

          That is pointer casting. Like in here

          Or also in here
          it is better to use for instance dynamic_cast or one of the others

          Z Offline
          Z Offline
          zxw2006063
          wrote on last edited by
          #4

          @koahnig Thanks. Then I can look it up from the pointer-casting.

          1 Reply Last reply
          0
          • dheerendraD dheerendra

            prm is the void argument for your onData function. wDsiplay must be the member variable inside the class TexoDemo. To access this variable you need to typecast the prm to TexoDemo type. If you don't typecast, wDisplay will not be able to access.
            display must be a function of wDisplay.

            Hope that clarifies.

            Z Offline
            Z Offline
            zxw2006063
            wrote on last edited by
            #5

            @dheerendra

            Thank you Dheerendra for your detailed explanation.
            I just have one more question. You said the wDisplay will not able to access if I don't do typecast. But I found another function defined in the same class as below:

            void TexoDemo::onAmp(int value)
            {
            wDisplay->setAmp(value);
            iDisplay->setAmp(value);
            }

            Why in this case the wDisplay can be accessed and no need to use the typecast? Sorry if the question is too simple. Thank you in advance.

            Regards
            XW

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              in the current case it is the current objects wDisplay variable u r accessing. In the previous case it is wDisplay of another object passed through prm variable.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              Z 1 Reply Last reply
              5
              • dheerendraD dheerendra

                in the current case it is the current objects wDisplay variable u r accessing. In the previous case it is wDisplay of another object passed through prm variable.

                Z Offline
                Z Offline
                zxw2006063
                wrote on last edited by
                #7

                @dheerendra
                Clear. Thank you.

                1 Reply Last reply
                1
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  move the issue to "Solved" state

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  4

                  • Login

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