main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <QDebug>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
ROS_INFO("Received \n");
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
qDebug() << "here";
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
cv::waitKey(10);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
qDebug() << "first";
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera/image", 10, imageCallback);
w.show();
ros::spin();
return a.exec();
}
Qt文件
#-------------------------------------------------
#
# Project created by QtCreator 2022-05-01T17:42:05
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Qt1
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += /opt/ros/melodic/include
LIBS += /opt/ros/melodic/lib/*so
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lopencv_core -lopencv_imgcodecs -lopencv_highgui
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
报错
undefined reference to symbol ‘_ZN2cv6String10deallocateEv