why it makes me error???:(- please help!
-
I have that code:
and this line of code:
this is public member in mainwindow.h,
and I wrote that
in sendCommand.cpp:
in SendCommand.cpp- I added includ:

But, as you see its maje me error and not recognized m_serial:(
waiting for your help:)@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); } -
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?
-
I have that code:
and this line of code:
this is public member in mainwindow.h,
and I wrote that
in sendCommand.cpp:
in SendCommand.cpp- I added includ:

But, as you see its maje me error and not recognized m_serial:(
waiting for your help:)@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); } -
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?
-
@RuWex said in why it makes me error???:(- please help!:
dont recognize m_serial
Because m_serial is part of MainWindow class...
-
@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); }