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. syntax guidance
Qt 6.11 is out! See what's new in the release blog

syntax guidance

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 661 Views 3 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.
  • C Offline
    C Offline
    CharlesHuff
    wrote on last edited by
    #1

    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();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You SysManager seem to be a singleton so why declare all these static variables ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CharlesHuff
        wrote on last edited by
        #3

        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,

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @CharlesHuff said in syntax guidance:

          sFoundation20.so

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CharlesHuff
            wrote on last edited by
            #5

            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....

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then if it is a C library, you should create a proper object to encapsulate its use through your application.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CharlesHuff
                wrote on last edited by
                #7

                @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

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mchinand
                  wrote on last edited by
                  #8

                  One way you can do it is to sub-class QMainWindow and have an instance of SysManager be a member of your MainWindow class. Then, create slots that call the various SysManager methods. Connect your buttons' clicked signals to these slots.

                  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