-2

I am facing an error when I tried to run ROS commands from qtquick appliction using system function in c++. Where as when i run some other simple cpp file consisting

system("roscore") 

it did work . But when i ran same function in qt app,

I got the following error

sh: 1: roscore: not found

So can anyone tell me what to do??

Edit : Link to code on github

  • 2
    Please, provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Moreover, [do not post errors as images](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – apalomer Feb 25 '18 at 17:14
  • Are your running the qt program from a terminal where `roscore` works? – apalomer Feb 25 '18 at 17:15
  • no i am not running qt programme from terminal...i am running it from editor – Abhishek Saini Feb 25 '18 at 17:16
  • It looks like i need to add some path to include commands, but i dont know how. – Abhishek Saini Feb 25 '18 at 17:16
  • Run it from the terminal to see if it is an environment problem. You probably do not have loaded in QtCreator all the paths and definitions that ROS needs. For further information on how to use QtCreator and ROS please visit: http://wiki.ros.org/IDEs#QtCreator – apalomer Feb 25 '18 at 17:18
  • actually i cant even create files from qt if I try system("touch something") , So maybe I need permissions?? – Abhishek Saini Feb 25 '18 at 17:19
  • 1
    Can you please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)? – apalomer Feb 25 '18 at 17:20
  • the link you told me tell that how to open packages n all in ros...it didnt told me how to include ros commands in qt programm – Abhishek Saini Feb 25 '18 at 17:22
  • No, the [link](http://wiki.ros.org/IDEs#QtCreator) that I gave you explains how to properly set up QtCreator IDE so it is not launched form the terminal: _As QtCreator supports opening CMake projects out of the box, it does not require a setup procedure it does not require a setup procedure if started from a terminal. Note that this is absolutely crucial, because otherwise the environment will not be set correctly and functionality related to rosbuild or catkin will fail when running cmake._ – apalomer Feb 25 '18 at 17:25
  • ya i got what you told me...but my project dont run on cmake it runs on qmake Well I am posting the link to code – Abhishek Saini Feb 25 '18 at 17:34
  • If you load QtCreator properly, as explained in the [link](http://wiki.ros.org/IDEs#QtCreator) I gave you. QtCreator will be loaded with all the ROS environment and your problem will most likely be solved. What they explain in the link has nothing to do with CMake but with loading the ROS environment into QtCreator. – apalomer Feb 25 '18 at 17:35
  • I think u wanted me to do a small edit in qtcreator.desktop file , Well I did that and there was no improvement. – Abhishek Saini Feb 25 '18 at 17:44
  • I tried to run my app from terminal then I got the error not found. Simply the terminal cant reach the library but no such error occur when I run the app from Qt Creator. So do u know how to resolve this? – Abhishek Saini Mar 03 '18 at 16:31

2 Answers2

0

I Don't Think Adding QML_IMPORT_PATH = /opt/ros/kinetic/bin Is Enough.

You Need To Source setup.bash first cause qt Console Don't Use .bashrc Environments.

Simplest Way Is To Source setup.bash At The Start Of Your Code Before Calling Any ros-based commands

EDIT1:

You can call Absolute Path To Your Executable for instance roscore will be /opt/ros/kinetic/bin/roscore

Mohammad Ali
  • 569
  • 4
  • 10
0

Just launch the Qt Creator app from the terminal and everything will work fine!

starball
  • 20,030
  • 7
  • 43
  • 238
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33444631) – Parisa.H.R Dec 21 '22 at 04:46