I am currently working on Ubuntu 14.04, using gcc 4.9.2 and Qwt 6.1.3; I have installed both Qt 4.8.6 and Qt 5.2.1 (and I wonder whether this could be connected to the issues I am experiencing).
I have a simple GUI with a QwtPlot and a QwtPlotCurve attached, which I am trying to update and redraw. In the setupUi() function, I create a few random data points and then plot them:
void ExampleMainWindow::setupUi(QMainWindow* mainWindow)
{
// run the inherited setupUi
Ui_MainWindow::setupUi(mainWindow);
// associate internal pointer to main window
this->mainWindow = mainWindow;
// create some data points
for(unsigned int i = 0; i < 10; i++)
{
this->createDataPoint();
}
for(unsigned int i = 0; i < this->xPlot.size(); i++)
{
cout << "Point #" << i << ": x=" << xPlot[i] << "; y=" << yPlot[i] << endl;
}
this->updateGraph();
// also, connect stuff
connect( this->pushButton, SIGNAL(clicked()), this, SLOT(synchronous()) );
return;
}
Now, this part works as it should. The result is something like this:
Later, I connected the pushButton to a method that should add 10 points to the curve and replot it. The relevant methods are:
void ExampleMainWindow::synchronous()
{
cout << "Creating 10 new data points..." << endl;
for(unsigned int i = 0; i < 10; i++) this->createDataPoint();
cout << "xPlot.size() = " << xPlot.size() << " ; yPlot.size() = " << yPlot.size() << endl;
this->updateGraph();
return;
}
void ExampleMainWindow::updateGraph()
{
// detach everything?
this->qwtPlot->detachItems();
// create a new curve
QwtPlotCurve* curve = new QwtPlotCurve("curve 1");
curve->setSamples( QVector<double>::fromStdVector( xPlot ), QVector<double>::fromStdVector( yPlot ) );
curve->attach( this->qwtPlot );
this->qwtPlot->replot();
//this->qwtPlot->show();
return;
}
Now, the issue is that pressing the pushButton on the GUI does not visually change anything in the QwtPlot. I am sure the program enters synchronous when the pushButton is clicked. So, there is probably something wrong with the function updateGraph, but I am missing something, as I cannot find the issue.
When I compile the project, I use Qt 4.8.6, with
qmake-qt4
make
and I get no compiling errors. My Qt project file is:
TEMPLATE = app
TARGET = example
QT += widgets
CONFIG += qwt
QMAKE_CXXFLAGS += -std=c++11
DEPENDPATH += ../. \
# for Qwt
/usr/local/qwt-6.1.3-svn/lib \
/usr/local/qwt-6.1.3-svn/include
# end for Qwt
INCLUDEPATH += ../. \
# for Qwt
/usr/local/qwt-6.1.3-svn/include
# end for Qwt
LIBS += -lqwt \
-L/usr/local/qwt-6.1.3-svn/lib
# Input
FORMS += example.ui
HEADERS = ExampleMainWindow.h
SOURCES = ExampleMainWindow.cpp \
main.cpp
Even looking at the examples I found online, I am unable to find the problem. Can you help me?
Thanks in advance for your support :-)
EDIT: The phrase pointing out the issue was cut out by mistake.
Ok, after several trials and errors, I found a solution: I installed Qwt (I guess 6.0) through Ubuntu's Software Center, and removed all the other Qwt versions (6.1.2 and 6.1.3) that I had manually installed. Now, the small GUI is working properly.
I guess the error was due to some issue in the paths I provided in the .pro file, but I could not pinpoint the exact mistake. Not really a satisfying answer, but at least it works.
Related
Asking this because i can't figure it out.
Environment: Windows 10 x64, Qt Creator 4.11.1, OpenCv 3.9, msvc 2017_64
I tried this as like the Qt Documentation says:
QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras();
for (const QCameraInfo &cameraInfo : availableCameras) {
std::cout << cameraInfo.description().toStdString() << std::endl;
}
if(availableCameras.isEmpty())
cout << availableCameras.size() << endl;
cout << "Empty" << endl;
But in output i get: "0, empty"
I don't know if it's a bug, but with another blank project without including OpenCv this code works. Can someone explain?
-EDIT-
I solved the problem deleting the directory
"build-ProjectName-Desktop_Qt_5_14_1_MSVC2017_64bit-Release"
So, i rebuilding and deploying with "windeployqt.exe ." in the directory of my project.exe
Im trying to use the inter-widget drag-and-drop functionalities in GTK3 with gtkmm. Im using Windows 7 x64 (msys2) and gcc 5.3.0.
When i start dragging, the mouse cursor vanishes and the DnD icon is shown at the upper left corner of the screen. Is this a bug or is there something wrong in my code?
Here you can see a very small test application with Gtk::CheckButton as drag source and drag destination.
#include <iostream>
#include <gtkmm-3.0/gtkmm.h>
struct DragButton : Gtk::CheckButton{
DragButton(){
this->signal_drag_begin().connect([](const Glib::RefPtr<Gdk::DragContext>& ctx){
ctx->set_icon();
});
this->drag_source_set({Gtk::TargetEntry("testdata")});
this->drag_dest_set({Gtk::TargetEntry("testdata")});
this->signal_drag_data_get().connect(
[this](const Glib::RefPtr<Gdk::DragContext>&,Gtk::SelectionData& s,guint,guint ){
std::cout << "sending data." << std::endl;
}
);
this->signal_drag_data_received().connect(
[](const Glib::RefPtr<Gdk::DragContext>& c,int,int,const Gtk::SelectionData&,guint,guint time){
std::cout << "receiving data" << std::endl;
c->drop_finish(true,time);
}
);
}
};
int main(){
auto app = Gtk::Application::create("test");
auto settings = Gtk::Settings::get_default();
settings->set_property<Glib::ustring>("gtk-font-name","Sans 10");
Gtk::Window window;
window.set_default_size(100,50);
Gtk::Box box;
for(int i = 0; i < 3; i++){
box.pack_end(*Gtk::manage(new DragButton));
}
window.add(box);
window.show_all();
app->run(window);
}
This screenshot shows the output:
I noticed the same behaviour here. Even with "official" gnome/gtk applications. For example, let's try to drag&drop widgets in Glade: you will have the same "strange" effect.
I think it's a bug of gtk libraries in Windows, but I can't imagine why this isn't solved yet, considering drag&drop is a very useful and used operation.
I found the problem. I found out here that the adwait-icon-theme that is used as a default was not fully windows-compatible. The cursors .cur format were missing. This commit fixed the problem, I had to install the new version of the theme.
I'm following this tutorial in the official PCL documentation for the class PCLVisualizer:
http://pointclouds.org/documentation/tutorials/pcl_visualizer.php
and I'm having troubles with the keyboard acquisition: when I select the render window, where the pointcloud is displayed, and try to press "r" or "q", nothing happens and when I try to press the mouse left button, the following text is displayed:
Left mouse button released at position (413, 475)
and the following error is raised (at runtime):
Assertion failed: (px != 0), function operator->, file /usr/local/include/boost/smart_ptr/shared_ptr.hpp, line 687.
Abort trap: 6
I saw that this kind of error happens when you don't initialize the boost::shared_ptr in the declaration of the variable. But in the code listed in the documentation the variable is well defined, so I suppose that the problem concerns the shared_ptr.hpp library, or it isn't?
I've searched over the Internet for a solution, but I haven't found nothing that could solve the issue.
Is there someone that is capable of acquiring keystrokes in the pointcloud's render window by running it on OS X?
If the question is not clear, please let me know.
Thanks a lot for any help or information!
You do not show any code so it's hard to tell what's wrong in your program.
Here is a working example, tested on Ubuntu 14.04 with PCL latest trunk (VTK trunk):
#include <iostream>
#include <pcl/visualization/pcl_visualizer.h>
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent &event, void* viewer_void)
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void);
if (event.getKeySym() == "r" && event.keyDown())
std::cout << "'r' was pressed" << std::endl;
if (event.getKeySym() == "h" && event.keyDown())
std::cout << "'h' was pressed" << std::endl;
}
void mouseEventOccurred(const pcl::visualization::MouseEvent &event, void* viewer_void)
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void);
if (event.getButton() == pcl::visualization::MouseEvent::LeftButton &&
event.getType() == pcl::visualization::MouseEvent::MouseButtonRelease)
std::cout << "Left mouse button released at position (" << event.getX() << ", " << event.getY() << ")" << std::endl;
}
int main()
{
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);
viewer->addCoordinateSystem();
viewer->registerKeyboardCallback(keyboardEventOccurred, (void*)&viewer);
viewer->registerMouseCallback(mouseEventOccurred, (void*)&viewer);
viewer->spin();
}
Note that some key-strokes are already used by the PCL visualizer for some actions (press h for more details), but it does not prevent you from using them as well.
I've been using OpenCV 3.0.0 for quite some time now and have recently switched IDEs from Visual Studio 2013 to Qt Creator 3.4.2. I rebuilt my OpenCV libraries from source WITH_QT checked. I'm now having a problem at runtime with deallocating a vector<vec4i> when using the HoughLinesP function ONLY in debug mode.
Here's a snippet of my code:
Mat source(400,400,CV_8U,Scalar(0));
line(source,Point(20,20),Point(300,300),Scalar(255),10);
{
vector<Vec4i> lines;
HoughLinesP(source, lines, 1, CV_PI/180, 50, 50, 10 );
cout << "lines.size() = " << lines.size() << endl;
cout << "before leaving block" << endl;
}
cout << "after leaving block" << endl;
imshow("source", source);
waitKey();
return 0;
If I run this in release, then everything works fine and this is my output:
lines.size() = 13
before leaving block
after leaving block
However, if I run this in debug, then my program crashes when it reaches the closing block and this is my output:
lines.size() = 18446744073709306522
before leaving block
If in debug and I comment out the line with HoughLinesP, then there is no crash and this is my output:
lines.size() = 0
before leaving block
after leaving block
Here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVProject_x64
TEMPLATE = app
INCLUDEPATH += C:\OpenCV3.0.0\opencv\build\include
win32:CONFIG(release, debug|release) {
LIBS += -LC:\OpenCV3.0.0\opencv\OpenCVLocalBuild_x64\lib\Release \
-lopencv_calib3d300 -lopencv_core300 -lopencv_features2d300 \
-lopencv_flann300 -lopencv_hal300 -lopencv_highgui300 \
-lopencv_imgcodecs300 -lopencv_imgproc300 -lopencv_ml300 \
-lopencv_objdetect300 -lopencv_photo300 -lopencv_shape300 \
-lopencv_stitching300 -lopencv_superres300 -lopencv_ts300 \
-lopencv_video300 -lopencv_videoio300 -lopencv_videostab300
}
win32:CONFIG(debug, debug|release) {
LIBS += -LC:\OpenCV3.0.0\opencv\OpenCVLocalBuild_x64\lib\Debug \
-lopencv_calib3d300d -lopencv_core300d -lopencv_features2d300d \
-lopencv_flann300d -lopencv_hal300d -lopencv_highgui300d \
-lopencv_imgcodecs300d -lopencv_imgproc300d -lopencv_ml300d \
-lopencv_objdetect300d -lopencv_photo300d -lopencv_shape300d \
-lopencv_stitching300d -lopencv_superres300d -lopencv_ts300d \
-lopencv_video300d -lopencv_videoio300d -lopencv_videostab300d
}
SOURCES += main.cpp
Please let me know if you have ideas on whats causing this crash.
qmake Language: Scope Syntax:
Scopes consist of a condition followed by an opening brace on the same
line, a sequence of commands and definitions, and a closing brace on a
new line:
<condition> {
<command or definition>
...
}
The opening brace must be written on the same line as the condition. Scopes may be concatenated to include more than one
condition, as described in the following sections.
Both library sets are added to the LIBS variable for Debug and Release build, since scope opening braces are written on the new line after conditions.
It appears that at least for Visual Studio 12 Win64 and OpenCV 3.0 there is binary incompatibility between Debug and Release libraries.
If the application is built in the Debug mode with the Release libraries it crashes and if it is built in the Release mode with the Debug libraries it also crashes.
i found this code for QT Creator and am brand new to the IDE, but have been trying to get this code to run. The main error I am seeing is about 12 instances of similar errors related to Qextserialport.
C:\Users\Hassman\Downloads\aQtLow\aQtLow\dtransferusb.cpp:
34: error: undefined reference to `QextSerialPort::QextSerialPort(QextSerialPort::QueryMode, QObject*)'
I'm not quite sure what to do about it, and am kind of lost. I am running QTCreator 5.1.1 and I imagine there may be a compatibility issue, but please someone give me a hand. Maybe I haven't linked the header to my file correctly? Any suggestions would be appreciated!
#include "dtransferusb.h"
#include <QDebug>
#include <QByteArray>
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport.h"
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport_p.h"
#include "globals.h"
dtransferusb::dtransferusb(QObject *parent) :
QThread(parent)
{
}
void dtransferusb::run()
{
SerPort= new QextSerialPort();
int ExpectedLength = NUMBER_OF_REGISTERS * 2 + NUMBER_OF_COILS / 8 + 1;
QTime Startup, Sleeper;
Startup.start();
while(!Shutdown)
{
if(SerPort->isOpen())
{//the port is open so check for data
Sleeper.start();
while((ExpectingResponse > 0) && (SerPort->bytesAvailable() < ExpectedLength))
{
msleep(25);
if(Sleeper.elapsed() > 5000) break;
}
if(SerPort->bytesAvailable() >= ExpectedLength)
{//data found
Receive(ExpectedLength);
}
else
{
if((ExpectingResponse > 2) && (Startup.elapsed() > 15000))
{
qDebug() << "DTxfrUsb " << QString::number(Cfg.DTxfrUsb) << " finds the lack of expected response utterly demoralizing " << SerPort->portName() << " " << QDateTime::currentDateTime().toString(TIMESTAMP_FORMAT);
P[Cfg.Prc].CommFailure();
ExpectingResponse = 0;
SerPort->close();
Sleeper.start();
while(Sleeper.elapsed() < 1000) msleep(100);
}
else
{
if(!WriteRequest())
{
Send(1,0,0); //Function 1 siginfies "gimme data"
}
}
}
}
else
{//need to open the port
SerPort->reset();
SerPort->setPortName(Cfg.Port);
SerPort->setBaudRate(BAUD9600);
SerPort->setDataBits(DATA_8);
SerPort->setStopBits(STOP_1);
SerPort->setFlowControl(FLOW_OFF);
SerPort->setParity(PAR_NONE);
SerPort->setTimeout(1000);
QextSerialPort is a 3rd-party library that is not affiliated with the official Qt Project. You can find it at https://code.google.com/p/qextserialport/ -- You will need to install QextSerialPort separately.
Some extra notes:
Since you are new, I recommend using Qt 5.2.1 instead. It has many new features and bug fixes over Qt 5.1.1.
"Qt Creator" is the name of the IDE, "Qt" is the name of the libraries. The current version of the IDE is Qt Creator 3.1, the current version of the libraries is Qt 5.2.1.
Qt has its own built-in QSerialPort class, which I recommend if you want to write your own code.
(1) To use these classes in your application, use the following include statement:
#include <QtSerialPort/QtSerialPort>
(2) To link against the module, add this line to your qmake .pro file:
QT += serialport
Qt Serial Port Documentation