Ploting an image with 'imshow' of opencv in webots - qt

hi I am using opencv in webots and I want to plot an image . This is the controller:
#include <webots/Robot.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace webots;
using namespace cv;
int main(int argc, char **argv){
Robot *robot = new Robot();
int timeStep = (int) robot->getBasicTimeStep();
while (robot->step(timeStep) != -1) {
Mat a1 = imread("/home/alireza/Desktop/1.jpg");
cv::imshow("test",a1);
};
delete robot;
return 0;
}
and this is the makefile:
OPENCV = `pkg-config opencv --cflags --libs`
LIBRARIES = $(OPENCV)
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
RESOURCES_PATH = $(WEBOTS_HOME)/projects/robots/robotis
CXX_SOURCES = $(wildcard *.cpp)
include $(WEBOTS_HOME_PATH)/resources/Makefile.include
I make it successfully but when I want to run it I face a runtime error about Qt :
[co] qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
[co] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
I really need help.

Related

Using DLL's in Qt: undefined reference

I want to use an SDK I got for using a scanner. I'm using Qt 5.3 with MingW32 (on Windows 7).
The very first test I wanted to build should just print the SDK version.
Here is my project file
QT += core
QT -= gui
TARGET = Kojak1
CONFIG += console
CONFIG -= app_bundle
KOJAKDIR = "C:/Program Files/Integrated Biometrics/IBScanUltimateSDK_x64"
TEMPLATE = app
INCLUDEPATH += $$KOJAKDIR/Include
SOURCES += main.cpp
LIBS +=-L$$KOJAKDIR/lib/ -lIBScanUltimate
and here is the source code
#include <QCoreApplication>
#include "stdio.h"
#include <windows.h>
#include "IBScanUltimateApi.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
IBSU_SdkVersion sdk_version;
IBSU_GetSDKVersion(&sdk_version);
printf("%s %s",sdk_version.File,sdk_version.Product);
return a.exec();
}
Unforturnately I get the message
D:\devt\QTProjects\Kojak1\main.cpp:10: error: undefined reference to `IBSU_GetSDKVersion#4'
when trying to compile the program.
My lib directory does contain IBScanUltimate.lib and IBScanUltimate.dll.

Boost in Qt: Installation and Symbol(s) not found for architectures x86_64

I am back to Qt and C++ programming after a year break. I am trying to install boost library into Qt on Mac (10.9.4) and I am completely confused. This is what I did:
I installed boost using homebrew.
I see that hpp files are installed here:
/usr/local/Cellar/boost/1.55.0_2/include/boost
and libraries here:
/usr/local/Cellar/boost/1.55.0_2/lib
Now I start a new Qt console project.
the project file:
QT += core
QT -= gui
TARGET = testQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/Cellar/boost/1.55.0_2
And the main file:
#include <QCoreApplication>
#include <QtCore>
#include <iostream>
#include <QDebug>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return a.exec();
}
Not compiling. Issues:
Symbol(s) not found for architectures x86_64
linker command failed with exist code 1
Since I am absolutely noob with boost, did I do it right? If yes, why is it not compiling?
Thanks a lot!
You need to link with boost too!
LIBS += -L/usr/local/Cellar/boost/1.55.0_2/lib -lboost

error: 'qmlRegisterType' was not declared in this scope

Working with Qt 5 and QtQuick 2.0
.pro
# Add more folders to ship with the application, here
folder_01.source = qml/untitled
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
#CONFIG += qt plugin
#QT += qml quick
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
../DummyClass.cpp \
../aa.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
../DummyClass.h \
../aa.h
main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "/home/***/qmllistproperties/DummyClass.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
const char* ocuui = "OCUUI"; // #uri OCUUI
qmlRegisterType <DummyClass> (ocuui, 1, 0, "DummyClass");
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
viewer.showExpanded();
return app.exec();
}
qmlRegisterType is in QtQml. You have to include QtQml:
#include <QtQml>

QT Systray icon appears next to launcher on Ubuntu instead of on the panel

I am new to QT and need to build an app with an app-indicator. As QT seems easier than GTK+, I am making it in QT.
I would mention that I have sni-qt installed and app indicators of vlc and skype appear normal on the panel. I am using QT5 on Ubuntu 13.04 64-bit.
I followed this tutorial step by step: http://qt-project.org/doc/qt-4.8/desktop-systray.html
But when I run it, here's how it appears (The cross is the icon I am using):
How do I fix this?
I'm afraid that Qt5 is not supported by sni-qt at the moment, so you either have to wait for a new release that will support it, or code it using gtk+ and libappindicator using this guide. There are even examples for various of languages. Since Qt5 also distributes GLib events that makes the integration a lot more easier. First you need to find out whether you're running on Unity or not (to support more desktops than just unity), that you can do by retrieving XDG_CURRENT_DESKTOP environment variable and if it returns Unity you create appindicator, otherwise create QSystemTrayIcon.
First you need to include required headers:
#undefine signals
extern "C" {
#include <libappindicator/app-indicator.h>
#include <gtk/gtk.h>
}
#define signals public
Since app-indicator directly uses "signals" name we need to undefine the default Qt "keyword" signals which normally translates to public. Then, since we're coding C++ and libappindicator is coded in C we need to use extern "C" not to use C++ name mangling.
Next create the AppIndicator/QSystemTrayIcon based on what desktop are we on:
QString desktop;
bool is_unity;
desktop = getenv("XDG_CURRENT_DESKTOP");
is_unity = (desktop.toLower() == "unity");
if (is_unity) {
AppIndicator *indicator;
GtkWidget *menu, *item;
menu = gtk_menu_new();
item = gtk_menu_item_new_with_label("Quit");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(item, "activate",
G_CALLBACK(quitIndicator), qApp); // We cannot connect
// gtk signal and qt slot so we need to create proxy
// function later on, we pass qApp pointer as an argument.
// This is useful when we need to call signals on "this"
//object so external function can access current object
gtk_widget_show(item);
indicator = app_indicator_new(
"unique-application-name",
"indicator-messages",
APP_INDICATOR_CATEGORY_APPLICATION_STATUS
);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_menu(indicator, GTK_MENU(menu));
} else {
QSystemTrayIcon *icon;
QMenu *m = new QMenu();
m->addAction(tr("Quit"), qApp, SLOT(quit()));
}
Finally we create the proxy function to call Qt signal from it, to declare the function we need to use extern "C" so there will not be any undefined behaviour.
extern "C" {
void quitIndicator(GtkMenu *, gpointer);
}
Now the proxy function:
void quitIndicator(GtkMenu *menu, gpointer data) {
Q_UNUSED(menu);
QApplication *self = static_cast<QApplication *>(data);
self->quit();
}
Just wanted to add, for anyone that is using Qt and trying to show a app indicator in Ubuntu 13+ as others have mentioned sni-qt is not working, I was able to use the above reply to make a Qt app that works, still trying to get the icon to change and show popup messages, but this is a great start, once i get the icon and message to work i might post it out on my site Voidrealms.com:
Be sure to do sudo apt-get install libappindicator-dev
Make a new project with a QDialog in it and modify as seen below:
Pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2014-03-28T20:34:54
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = PluginServiceGUI
TEMPLATE = app
# includes for the libappindicator
# /usr/lib/x86_64-linux-gnu libglib-2.0.a
INCLUDEPATH += "/usr/include/libappindicator-0.1"
INCLUDEPATH += "/usr/include/gtk-2.0"
INCLUDEPATH += "/usr/include/glib-2.0"
INCLUDEPATH += "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
INCLUDEPATH += "/usr/include/cairo"
INCLUDEPATH += "/usr/include/pango-1.0"
INCLUDEPATH += "/usr/lib/x86_64-linux-gnu/gtk-2.0/include"
INCLUDEPATH += "/usr/include/gdk-pixbuf-2.0"
INCLUDEPATH += "/usr/include/atk-1.0"
LIBS += -L/usr/lib/x86_64-linux-gnu -lgobject-2.0
LIBS += -L/usr/lib/x86_64-linux-gnu -lappindicator
LIBS += -L/usr/lib/x86_64-linux-gnu -lgtk-x11-2.0
#These seem to not be needed
#LIBS += -L/usr/lib/x86_64-linux-gnu -lcairo
#LIBS += -L/usr/lib/x86_64-linux-gnu -lpango-1.0
#LIBS += -L/usr/lib/x86_64-linux-gnu -lglib-2.0
# end incudes for libappindicator
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
FORMS += dialog.ui
RESOURCES += \
resources.qrc
In the main.cpp
#include "dialog.h"
#include <QApplication>
#include <QtGui>
#include <QSystemTrayIcon>
#include <QMessageBox>
#include <QSystemTrayIcon>
#include <QMenu>
// http://stackoverflow.com/questions/17193307/qt-systray-icon-appears-next-to-launcher-on-ubuntu-instead-of-on-the-panel
// requires libappindicator-dev
// sudo apt-get install libappindicator-dev
// installs the headers in: /usr/include/libappindicator-0.1/libappindicator
#undef signals
extern "C" {
#include <libappindicator/app-indicator.h>
#include <gtk/gtk.h>
void quitIndicator(GtkMenu *, gpointer);
}
#define signals public
void quitIndicator(GtkMenu *menu, gpointer data) {
Q_UNUSED(menu);
QApplication *self = static_cast<QApplication *>(data);
self->quit();
}
void ShowUnityAppIndicator()
{
AppIndicator *indicator;
GtkWidget *menu, *item;
menu = gtk_menu_new();
item = gtk_menu_item_new_with_label("Quit");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(item, "activate",
G_CALLBACK(quitIndicator), qApp); // We cannot connect
// gtk signal and qt slot so we need to create proxy
// function later on, we pass qApp pointer as an argument.
// This is useful when we need to call signals on "this"
//object so external function can access current object
gtk_widget_show(item);
indicator = app_indicator_new(
"unique-application-name",
"indicator-messages",
APP_INDICATOR_CATEGORY_APPLICATION_STATUS
);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_menu(indicator, GTK_MENU(menu));
}
void ShowQtSysTray(QApplication* app, QDialog* dialog)
{
Q_INIT_RESOURCE(resources);
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
}
QApplication::setQuitOnLastWindowClosed(false);
QSystemTrayIcon* trayIcon = new QSystemTrayIcon(dialog);
QAction* Action = new QAction("hello", dialog);
QMenu* trayIconMenu = new QMenu(dialog);
trayIconMenu->addAction("Quit", app, SLOT(quit()));
trayIconMenu->addAction(Action);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon (":/icons/Icons/accept.png"));
trayIcon->show();
trayIcon->showMessage("Title","Message");
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
//Determine the desktop type
QString desktop;
bool is_unity;
desktop = getenv("XDG_CURRENT_DESKTOP");
is_unity = (desktop.toLower() == "unity");
if(is_unity)
{
ShowUnityAppIndicator();
}
else
{
//Show the SystemTrayIcon the Qt way
ShowQtSysTray(&a, &w);
}
// w.show();
return a.exec();
}

missing std::runtime_error in qt+mingw

I've tried to compile the following code using Qt(4.6.3) + MinGW:
#include <QtCore/QCoreApplication>
#include <exception>
int main(int argc, char *argv[])
{
throw std::runtime_error("");
QCoreApplication a(argc, argv);
return a.exec();
}
... and got this error:
..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std'
Project created from scratch(console application), the pro file:
QT += core
QT -= gui
TARGET = untitled11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Tried to compile this using Qt+MSVC2008 compiler - works fine.
This is a standard exception, have no idea why is missing.
<exception> defines only the base std::exceptionclass; if you want child classes like std::runtime_error, you must include the <stdexcept> header.

Resources