syntax guidance
-
in the past I declared multiple instances of SysManager inside each part of Qt 4 that called on_button_clicked()... I think that was wrong usage. Please see example code:
std::vector<std::string> comHubPorts; size_t portCount = 0; QString myStr; QString myStr2; QString myStr3; sFnd::SysManager *myMgr; sFnd::IPort *iPort; sFnd::INode *theNode; int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; w.show(); myMgr = sFnd::SysManager::Instance(); myMgr->sFnd::SysManager::FindComHubPorts(comHubPorts); myStr = QString::number(comHubPorts.size()); qInfo() << "Found:" << myStr; myStr2 = comHubPorts[0].c_str(); qInfo() << "Device: " << myStr2; myMgr->ComHubPort(0, comHubPorts[0].c_str()); myMgr->PortsOpen(0); iPort = &myMgr->Ports(0); qDebug() << "NetNumber: " << QString::number(iPort->NetNumber()); qDebug() << "OpenState: " << QString::number(iPort->OpenState()); qDebug() << "Node: " << QString::number(iPort->NodeCount()); //myMgr->PortsClose(); I want to do this in void Dialog::on_pushButton_clicked() return a.exec(); } -
Hi,
You SysManager seem to be a singleton so why declare all these static variables ?
-
do you mean the code before main()? It's my ignorant attempt to make SysManager *myMgr variables "Public" or at least usable outside of the main() function. SysManager is from sFoundation20.so library. Their examples do not seem to be for c++ and I am struggling to discover how to use the library with Qt 6 creator...
Thanks,
-
@CharlesHuff said in syntax guidance:
Where does that library come from ?
From the looks of it, you need to take a step back and rethink your application design. What should it do ?
-
it is their hello world! it opens a com port and assigns a node on the port to a servo motor. www.teknic.com is the address. you have to create an account to get all the manuals. the code is working and outputting results that I can see in qDebug() comments. I don't want to only use the code from main() function but also from buttons, ect....
-
Then if it is a C library, you should create a proper object to encapsulate its use through your application.
-
@SGaist said in syntax guidance:
application
I have only their examples to look at. I googled encapsulation in c++ and it looks like it is done with Classes in c++ so I will work on understanding that. There seems to be an Axis class. I have only one motor = one Axis so maybe I can figure it out.
Thanks,
Charles