[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users


Hi,

I am trying run some ros2 command directly inside Qt, but I don't know how to set up Qt's environment or how run the `setup.bash` file inside Qt?

For example, I tried:
`system(qPrintable(.  ~/ros2_install/ros2-osx/setup.bash));`    in Qt, and get the error as following:

env: python3: No such file or directory
error: unable to find fallback python3 executable


I know there is one way that I can source the `setup.bash` file in Terminal and run Qt from this Terminal, but is there a method to run the setup.bash file directly inside Qt?





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/1) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users


I'm not sure what this has to do specifically with ROS 2. The general issue here is how do you source a shell script correctly via a system call.

I recommend asking on a more generic forum. We usually use Python's `subprocess` module to do this kind of thing.





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/2) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Hi,what do you mean by running inside Qt ? Building an application that uses Qt and ROS2 or opening a ROS2 package inside the Qt Creator IDE ? In the second case I'd say it is easier to open a bash. Then source the ros2_ws and your own workspace. (See also https://discourse.ros.org/t/trouble-opening-package-in-qtcreator/2196/5)
and then start qtcreator in this terminal.

In the first case you have to adjust your CMakeLists.txt (For example like that: https://github.com/firesurfer/ros2_components/blob/master/CMakeLists.txt)

The relevant lines are:
    find_package(Qt5Core REQUIRED)
    find_package(Qt5Network REQUIRED)
    find_package(Qt5Widgets REQUIRED)

and
   set(CMAKE_AUTOMOC ON)
   set(CMAKE_AUTOUIC ON)
   set(CMAKE_INCLUDE_CURRENT_DIR ON)

And in the CMakeLists that acutally adds targets ( https://github.com/firesurfer/ros2_components/blob/master/src/ros2_components/CMakeLists.txt)

include_directories(
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5Network_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS}

    )

and

target_link_libraries(<your target name>
    Qt5::Core
    Qt5::Network
    Qt5::Widgets

)





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/3) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Hi,
What I meant is just like what wjwwood writes: I need to source a shell script via a system call inside Qt.

Your method of sourcing the terminal and then open qt with this terminal works for sure, but do you have any experience to run the "sourcing command" directly in Qt using system call?

If not, then I guess I'll ask this in a more generic forum like he said.

But still, thanks for your answer!





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/4) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


My question is still. Do you mean qt or qtcreator? Thats a huge difference. In qtcreator (the ide) there is somewhere at the project tab the possibilty to set a custom build / run environment.

Doing a systemcall for sourcing doesn't make any sense. But running a qt application together with ros2 without sourcing before is also possible.
The script doesn't do anything else than setting some environment variables.
You could set the variables by hand using: https://stackoverflow.com/questions/899517/set-local-environment-variables-in-c

Edit: See https://stackoverflow.com/questions/11272720/how-to-run-source-command-in-c why running source via a systemcall doesnt work and also doesn't make sense.





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/5) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


oh sorry I didn't understand that, I meant qtCreator(the ide).





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/6) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] ROS2: running command inside Qt?

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Then sourcing before is the easiest possibility.
See https://stackoverflow.com/questions/30246742/setting-environment-variables-at-qt-creator-by-sourcing-a-shell-script

Otherwise:
[quote="firesurfer, post:5, topic:2673"]
In qtcreator (the ide) there is somewhere at the project tab the possibilty to set a custom build / run environment.
[/quote]

https://doc-snapshots.qt.io/qtcreator-4.0/creator-build-settings.html





---
[Visit Topic](https://discourse.ros.org/t/ros2-running-command-inside-qt/2673/7) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>