Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. scope problems

scope problems

Scheduled Pinned Locked Moved Solved C++ Gurus
6 Posts 3 Posters 1.4k 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.
  • C Offline
    C Offline
    CharlesHuff
    wrote on last edited by
    #1

    I am trying to call library functions from within the Qwidget application.

    it looks something like this:
    SysManager myMgr;
    IPort *iPort;
    SysManager::FindComHubPorts(comHubPorts);
    myMgr.ComHubPort(0, "/dev/ttyXRUSB0");
    myMgr.PortsOpen(1);
    IPort &myPort = myMgr.Ports(0);
    INode &theNode = myPort.Nodes(0);

    followed by:
    theNode.Status.RT.Refresh();

    It would be desirable to be able to call the "theNode.Status.RT.Refresh();" from a Qt button or from within some other function other than QMainwindow. I tried putting SysManager myMgr; before the QMainWindow constructor, but I get "error, not declared in this scope". What then is the correct way to call the member functions of the library from a button in Qt? I can provide complete code if that would help clarify. Thanks

    jsulmJ 1 Reply Last reply
    0
    • C CharlesHuff

      I am trying to call library functions from within the Qwidget application.

      it looks something like this:
      SysManager myMgr;
      IPort *iPort;
      SysManager::FindComHubPorts(comHubPorts);
      myMgr.ComHubPort(0, "/dev/ttyXRUSB0");
      myMgr.PortsOpen(1);
      IPort &myPort = myMgr.Ports(0);
      INode &theNode = myPort.Nodes(0);

      followed by:
      theNode.Status.RT.Refresh();

      It would be desirable to be able to call the "theNode.Status.RT.Refresh();" from a Qt button or from within some other function other than QMainwindow. I tried putting SysManager myMgr; before the QMainWindow constructor, but I get "error, not declared in this scope". What then is the correct way to call the member functions of the library from a button in Qt? I can provide complete code if that would help clarify. Thanks

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

      @CharlesHuff Not sure where this code is actually located.
      But why don't you put

      SysManager myMgr;
      

      as class member in your MainWindow class?

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

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

        I googled "add a class member to your QMainWindow"...
        assuming I can figure out the proper syntax, are you saying that putting:
        SysManager myMgr; inside the QMainWindow function will make theNode.Status.RT.Refresh(); available inside of the void on_click_button function that is outside of QMainWindow? I put everything before the "followed by:" above in the QMainWindow function and it worked only inside of QMainWindow, not within the button's on_click function...

        My desire is to setup the variables of the library inside QMainWindow and then later manipulate them from button presses...

        I know you answer is very likely correct, I just don't know how to do that...

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

          Hi,

          See the c++ classes tutorial.

          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
          2
          • C Offline
            C Offline
            CharlesHuff
            wrote on last edited by
            #5

            putting " SysManager myMgr; " into each function that calls theNode.Status.RT.Refresh(); works! I am also amazed that Qt seems to somehow 'know' all the member function names now...

            I am starting to like c++ more every day!

            Thanks

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

              Qt is just C++. Creating a SysManager object in each function might not be the best idea. Having one instance in your class will make you code cleaner. Note that this doesn't apply to every situation.

              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
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved