Use an external value
-
Hi, we are working on a ROS project. We are trying to make an interface for a robot works with ROS.
In ROS system, we have C++ files called publishers and subscribers. Publishers mainly publish some values and subscribers reads them. It is kind of a communication between different files.
In our interface, we would like to show these values. A publisher will publish and a subscriber will read it. After reading, we should display it on our interface. We thought that we can send that value externally. Because both Qt files and Subscriber files are C++ files.
Can someone show me an example that mainwindow.cpp file that can externally shows a value?
-
@JonB I am a complete noob so I am open to any suggestion. Just want to send a variable's value of a different C++ file to the mainwindows.cpp as an external variable. Also want to show it on the interface, I don't know which component should I use (QuickWidget or PlainText...).
This variable will change with time so it has to renewed in a period.
Just need an example like this so I can implement it to our very-complicated subscriber file.
I will try what you said, thank you. If you have any other way or an example looks like this, that makes me very happy.
@aliemrenebiler
Qt paradigm is based on Signals & Slots. You need to read this for a basic understanding.Somehow, I think, your subscriber gets notified when the publisher pushes some data? If so, that is where you would have it
emit
a (user-defined) signal to indicate this, and your main window Ui would have a slot on that. The signal would pass the data to the slot, or the slot would query to subscriber to access the data, which can then be shown on the UI. If you do not have some explicit notification from the subscriber when it receives new data from the publisher, you would have to "poll" the subscriber via aQTimer
from the UI.I don't know which component should I use (QuickWidget or PlainText...).
Qt offers two different kinds of UI applications. The "normal"/"traditional" one is widgets. Once you start mentioning "Quick" anything you are talking about QtQuick/QML, which is a quite different programming paradigm, and the UI looks different. I cannot tell you which you would want to adopt for your UI, it could be either. You would have to Google for something like
Qt widgets vs QML
is you want to compare them. -
Hi, we are working on a ROS project. We are trying to make an interface for a robot works with ROS.
In ROS system, we have C++ files called publishers and subscribers. Publishers mainly publish some values and subscribers reads them. It is kind of a communication between different files.
In our interface, we would like to show these values. A publisher will publish and a subscriber will read it. After reading, we should display it on our interface. We thought that we can send that value externally. Because both Qt files and Subscriber files are C++ files.
Can someone show me an example that mainwindow.cpp file that can externally shows a value?
@aliemrenebiler
Not sure what you expect as an answer from this description. If your external C++ files have an interface which can be called defined in a.h
file, include that into Qt'smainwindow.cpp
and call functions as required. If you can edit the subscriber code so that upon read you can make itemit
a Qt signal, you can then write a slot inmainwindow.cpp
to be notified. -
@aliemrenebiler
Not sure what you expect as an answer from this description. If your external C++ files have an interface which can be called defined in a.h
file, include that into Qt'smainwindow.cpp
and call functions as required. If you can edit the subscriber code so that upon read you can make itemit
a Qt signal, you can then write a slot inmainwindow.cpp
to be notified.@JonB I am a complete noob so I am open to any suggestion. Just want to send a variable's value of a different C++ file to the mainwindows.cpp as an external variable. Also want to show it on the interface, I don't know which component should I use (QuickWidget or PlainText...).
This variable will change with time so it has to renewed in a period.
Just need an example like this so I can implement it to our very-complicated subscriber file.
I will try what you said, thank you. If you have any other way or an example looks like this, that makes me very happy.
-
@JonB I am a complete noob so I am open to any suggestion. Just want to send a variable's value of a different C++ file to the mainwindows.cpp as an external variable. Also want to show it on the interface, I don't know which component should I use (QuickWidget or PlainText...).
This variable will change with time so it has to renewed in a period.
Just need an example like this so I can implement it to our very-complicated subscriber file.
I will try what you said, thank you. If you have any other way or an example looks like this, that makes me very happy.
@aliemrenebiler
Qt paradigm is based on Signals & Slots. You need to read this for a basic understanding.Somehow, I think, your subscriber gets notified when the publisher pushes some data? If so, that is where you would have it
emit
a (user-defined) signal to indicate this, and your main window Ui would have a slot on that. The signal would pass the data to the slot, or the slot would query to subscriber to access the data, which can then be shown on the UI. If you do not have some explicit notification from the subscriber when it receives new data from the publisher, you would have to "poll" the subscriber via aQTimer
from the UI.I don't know which component should I use (QuickWidget or PlainText...).
Qt offers two different kinds of UI applications. The "normal"/"traditional" one is widgets. Once you start mentioning "Quick" anything you are talking about QtQuick/QML, which is a quite different programming paradigm, and the UI looks different. I cannot tell you which you would want to adopt for your UI, it could be either. You would have to Google for something like
Qt widgets vs QML
is you want to compare them.