[Documentation] [TitleIndex] [WordIndex

Overview

This works very much like the roscreate-pkg script. It sets up a simple ros package structure and includes a few extra qt files and appropriately configured CMakeLists.txt so that you can immediately build a very simple qt gui program.

Layout

Usage

Creating the Package

Use in the same way as roscreate-pkg.

roscreate-qt-pkg qtest

Building

You should be able to just do make immediately and run the resulting binary from the bin folder.

Extending the Ui

roscd qtest
designer ui/main_window.ui

Whenever you make modifications to the ui file, be sure to do a make clean before rebuilding to refresh the ui header.

Rosifying

You'll probably want to attach an ros node to the process. There are several ways of doing this, a very example follows. A more integrated way of doing so is to make use of the roscreate-qt-ros-pkg template.

#include <QtGui>
#include <QApplication>
#include <ros/ros.h>
#include <ecl/threads/thread.hpp> // or boost threads if you prefer
#include "../include/qkorus/main_window.hpp"

class Spinner {
public:
        Spinner() :
                shutdown_required(false),
                thread(&Spinner::spin, *this)
        {}

        ~Spinner() {
                shutdown_required = true;
                thread.join();
        }

        void spin() {
                ros::Rate loop(10);
                sleep(1);
                while ( ros::ok() && !shutdown_required ) {
                        ros::spinOnce();
                        loop.sleep();
                }
        }

private:
        bool shutdown_required;
        ecl::Thread thread; // similarly, a boost thread 
};

/*****************************************************************************
** Main
*****************************************************************************/

int main(int argc, char **argv) {

    ros::init(argc,argv,"qkorus");
    ros::NodeHandle node;
    Spinner spinner;

    QApplication app(argc, argv);
    qkorus::MainWindow w;  // automatically starts spinning a qgoo node inside
    w.show();
    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    int result = app.exec();
    return result;
}

2024-12-28 14:55