I have an Error in my terminal :device not open- but usually it works...C++
-
@JonB said in I have an Error in my terminal :device not open- but usually it works...C++:
This does not correspond to any "idea you [I] brought up".
I do not know how you initialised mainSend->mainwind.
Since the error says "QIODevice::write (QSerialPort): device not open" presumably that tells you that whatever you are doing the QSerialPort *serial used in serial->write() is not open.I forgot to upload another piece of code:
MainSendCommand:
MainSendCommand::MainSendCommand() { sendCommand= new SendCommands(); mainwind= new MainWindow(); }
I did it because I didnt want to do using mainWindow in Send Command file...
so what can be the problem?
I dont understand:( -
@RuWex said in I have an Error in my terminal :device not open- but usually it works...C++:
so what can be the problem?
I dont understand:(@JonB said in I have an Error in my terminal :device not open- but usually it works...C++:
@RuWex
Mostly understand why creating a newMainWindow
cannot be the right thing to do.I assume the
mainwind= new MainWindow();
you show inMainSendCommand::MainSendCommand()
is not the onlyMainWindow
your application creates, and is not theMainWindow
widget your application is actually showing. Until you understand the basics of C++ and what separate instances are you won't get very far.I already suggested one of simpler alternatives is to pass
m_serial
(once opened!) toSendCommands
orStartToSendCommand()
. You have no need to be trying to accessMainWindow
fromStartToSendCommand()
. -
@RuWex said in I have an Error in my terminal :device not open- but usually it works...C++:
Do you have any Idea how to get the instance that already open?
Like I said, do not try to pass or access the
MainWindow
instance you have created toMainSendCommand
(or any other class). A good rule of thumb is do not allow yourself to go#include "mainwindow.h"
in any file other thanmainwindow.cpp
, then you can never access it from elsewhere.Assuming you create the
MainSendCommand
instance from yourMainWindow
(right?). So pass the serial port instance instead. Like maybe:// Somewhere in `MainWindow` mainSendCommand = new MainSendCommand(m_serial); MainSendCommand::MainSendCommand(QSerialPort *serial) { sendCommand= new SendCommands(serial); } SendCommands::SendCommands(QSerialPort *serial) { this->m_serial = serial; } void SendCommands::StartToSendCommand( QString fileName) { m_serial->write(); }
-
@RuWex said in I have an Error in my terminal :device not open- but usually it works...C++:
But I didn't make an appearance of the class in mainSenfCommand
I take that to mean "code does not create any instance of
MainSendCommand
"? Or do you create it somewhere? Else what is the point of having it? What does theMainSendCommand
class do/add to your design? Maybe you don't need it andMainWindow
should just create aSendCommands
instance directly? This now all comes down to your overall program architecture. -
@RuWex said in I have an Error in my terminal :device not open- but usually it works...C++:
sendCommand need function to mainwindow
Now that you know nothing should need or hold any reference to
MainWindow
maybe you can get rid of thisMainSendCommand
class and simplify.