Important: Please read the Qt Code of Conduct -

scope problems

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

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

    followed by:

    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

  • Lifetime Qt Champion

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

    SysManager myMgr;

    as class member in your MainWindow class?

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

  • Lifetime Qt Champion


    See the c++ classes tutorial.

  • 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!


  • Lifetime Qt Champion

    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.

Log in to reply