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. why it makes me error???:(- please help!

why it makes me error???:(- please help!

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 406 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
    RuWex
    wrote on last edited by
    #1

    I have that code:1.PNG
    and this line of code:
    2.PNG
    this is public member in mainwindow.h,
    and I wrote that 1.PNG
    in sendCommand.cpp:3.PNG
    in SendCommand.cpp- I added includ:
    c325ae32-dce3-4dc1-a958-f68a8779ecb4-image.png
    But, as you see its maje me error and not recognized m_serial:(
    1.PNG
    waiting for your help:)

    jsulmJ 1 Reply Last reply
    0
    • R RuWex

      I have that code:1.PNG
      and this line of code:
      2.PNG
      this is public member in mainwindow.h,
      and I wrote that 1.PNG
      in sendCommand.cpp:3.PNG
      in SendCommand.cpp- I added includ:
      c325ae32-dce3-4dc1-a958-f68a8779ecb4-image.png
      But, as you see its maje me error and not recognized m_serial:(
      1.PNG
      waiting for your help:)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #3

      @RuWex You should learn basics of C++.
      You put m_serial in MainWindow class, but you're trying to access it from SendCommand class - this can't work this way. If m_serial is not static you need an instance of WmainWindow to access it like:

      MainWindow mw;
      mw.m_serial->...
      

      But this would be very bad design! You should not access internal members of other classes directly. If you really need to have m_serial in MainWindow then make it private and implement public methods to trigger actions on it, like:

      class MainWindow...
      public:
          void writeSerial(const QByteArray data) { m_serial->write(data); }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      2
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #2

        so you are essentially executing

        (static_cast<QSerialPort*>(0U))->write(line[i])
        

        and you don't understand why it wont work? Is that the gist of it?

        If you meet the AI on the road, kill it.

        R 1 Reply Last reply
        0
        • R RuWex

          I have that code:1.PNG
          and this line of code:
          2.PNG
          this is public member in mainwindow.h,
          and I wrote that 1.PNG
          in sendCommand.cpp:3.PNG
          in SendCommand.cpp- I added includ:
          c325ae32-dce3-4dc1-a958-f68a8779ecb4-image.png
          But, as you see its maje me error and not recognized m_serial:(
          1.PNG
          waiting for your help:)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @RuWex You should learn basics of C++.
          You put m_serial in MainWindow class, but you're trying to access it from SendCommand class - this can't work this way. If m_serial is not static you need an instance of WmainWindow to access it like:

          MainWindow mw;
          mw.m_serial->...
          

          But this would be very bad design! You should not access internal members of other classes directly. If you really need to have m_serial in MainWindow then make it private and implement public methods to trigger actions on it, like:

          class MainWindow...
          public:
              void writeSerial(const QByteArray data) { m_serial->write(data); }
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          2
          • Kent-DorfmanK Kent-Dorfman

            so you are essentially executing

            (static_cast<QSerialPort*>(0U))->write(line[i])
            

            and you don't understand why it wont work? Is that the gist of it?

            R Offline
            R Offline
            RuWex
            wrote on last edited by
            #4
            This post is deleted!
            jsulmJ 1 Reply Last reply
            0
            • R RuWex

              This post is deleted!

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @RuWex said in why it makes me error???:(- please help!:

              dont recognize m_serial

              Because m_serial is part of MainWindow class...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @RuWex You should learn basics of C++.
                You put m_serial in MainWindow class, but you're trying to access it from SendCommand class - this can't work this way. If m_serial is not static you need an instance of WmainWindow to access it like:

                MainWindow mw;
                mw.m_serial->...
                

                But this would be very bad design! You should not access internal members of other classes directly. If you really need to have m_serial in MainWindow then make it private and implement public methods to trigger actions on it, like:

                class MainWindow...
                public:
                    void writeSerial(const QByteArray data) { m_serial->write(data); }
                
                R Offline
                R Offline
                RuWex
                wrote on last edited by
                #6

                @jsulm ou!!!!
                thank you!
                I dont know what happend to me...:(
                sure, you right:)

                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