GUI gets blank while processing - c++

I have an application which runs a function in background, Here is my main class
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
#include "ogr_srs_api.h"
#include <QDir>
#include <QFile>
#include <QDebug>
#include <iostream>
#include <cstring>
#include <string>
#include <QFileDialog>
#include <QThread>
#include <QtConcurrent/QtConcurrent>
#include "databasemanager.h"
#include <sqlite_connection.h>
#include "locationinfo.cpp"
#include "gdal_wrap.h"
#include "gdalwarper.h"
#include "gdal_dem.h"
#include "shapefile_importer.h"
#include "gdal_contour.h"
using namespace QtConcurrent;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->startProcess, SIGNAL (released()), this, SLOT (StartProcess()));
}
void MainWindow::StartProcess(){
sendinfo("Starting Process... Note that the input images <b>must<\b> be in ESPG:3857.");
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if(dir==""){
sendwarning("nothing is selected.");
return;
}
sendinfo("The selected folder is: "+dir);
QFuture<void> f1 = run(std::bind1st(std::mem_fun(&MainWindow::RunProcess), this),dir);
f1.waitForFinished();
}
void MainWindow::RunProcess(QString dir){
......
}
MainWindow::~MainWindow()
{
delete ui;
}
As you can see I am running my function in a QtConcurrent function, so based on my googles there must not any blank GUI but when I run application it makes GUI blank in linux and if I do not click some place on GUI it will close my application.
What am I doing wrong here?

Related

Qt - How to find children right

I'm trying to find a widget that I added to the screen and do some manipulations with it, but the list of children is empty every time. What am I doing wrong?
Here is the code (to run it, create a new clean project and replace the text in MainWindow.cpp):
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QLabel>
#include <QLayout>
#include <QList>
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QLabel* wid = new QLabel("hello");
ui->centralWidget->layout()->addWidget(wid);
QList<QLabel*> list = ui->centralWidget->findChildren<QLabel*>();
qDebug() << list.isEmpty();
}
MainWindow::~MainWindow()
{
delete ui;
}

qt5 error occur Poppler::Document* document

I'm making PDF viewer using qt and poppler library but, the error occurred running this program
error was 'The program has unexpectedly finished.' error
occur Poppler::Document* document =
Poppler::Document::load(filename);
When I erase Poppler::Document::load(filename) error not occurred
How to solve it?
I found an error code below but follow this example poppler Qt5
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/opencv.hpp>
#include <QFileDialog>
#include <QMessageBox>
#include <QDesktopServices>
#include <QUrl>
#include <poppler-qt5.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("/home/googolhkl/사진/IMG_20150925_1.jpg");
cv::imshow("display",image);
QString filename;
Poppler::Document* document = Poppler::Document::load(filename);
if (!document || document->isLocked()) {
// ... error message ....
delete document;
return;
}
}
You have to load existing file, but in your example the file name is empty:
QString filename;

sending a dbus message from shell to qt app

I want to do dbus-send from shell/console to a qt application.
This is the code for a simple QT app
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QtDBus>
#include <QDBusConnection>
#include <QDebug>
MainWindow::~MainWindow()
{
delete ui;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
bool ret = QDBusConnection::sessionBus().connect(
"MyHome", //service
"/", //path
"com.mydomain.mcp", //interface
"usb", //name
this, //receiver
SLOT(messageSlot(QString)));
}
void MainWindow::messageSlot(const QString &t1)
{
qDebug("%s", QString("%1").arg(t1).toUtf8().data());
}
From the terminal, I and sending this command
dbus-send --session --print-reply --reply-timeout=2000 --type=method_call / com.mydomain.mcp.usb string:'a'
I get this error: Method "usb" with signature "s" on interface "com.mydomain.mcp" doesn't exist
What am I doing wrong?
Thanks

How to save bandwidth when using QGraphicsview with X-redirection

I have a large QGraphicsScene that I want to display, currently done by QGraphicsView.
When using locally everything is fine, but as soon as I use the App with ssh -X it is terribly slow. Of course some data always has to be transferred, but how could the bandwidth be saved if nothing changes, for example when only panning the image?
This is my QGraphicsView:
#include "graphicsview.h"
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QDebug>
#include <QMouseEvent>
#include <QWheelEvent>
#include <cmath>
#include <QPixmapCache>
GraphicsView::GraphicsView(QWidget *parent) :
QGraphicsView(parent)
{
QPixmapCache::setCacheLimit(16777216); //did not do the trick either
this->setMouseTracking(true);
setTransformationAnchor(AnchorUnderMouse);
this->setDragMode(QGraphicsView::ScrollHandDrag);
scene = new QGraphicsScene(this);
setScene(scene);
background = QPixmap(8000,8000);
qDebug() << background.rect();
scene->setSceneRect(background.rect());
scene->setBackgroundBrush(QBrush(background));
show();
}
void GraphicsView::wheelEvent(QWheelEvent* event) {
scale(pow(2,event->delta()/240.0), pow(2,event->delta()/240.0));
}

Qt + OpenCV grayscale error

I been trying to make a simple interface for an image processing task using OpenCV with C++ using Qt for the GUI.
I'm able to load the image through the GUI but when I press the pushbutton_3,
to convert the image to grayscale gives an error regarding OpenCV.
I'm sure I'm doing something wrong. Can some one give me a help?
Please see below the files:
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileDialog>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/types_c.h>
#include <opencv2/imgproc/imgproc.hpp>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::MainWindow *ui;
//Images variables
cv::Mat image_Idl;
cv::Mat image_Lit;
cv::Mat image_Idl_G;
cv::Mat image_Lit_G;
double threshHold;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/types_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <QSpinBox>
#include <QSlider>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->horizontalSlider->setRange(0,255);
ui->spinBox->setRange(0,255);
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),ui->spinBox,SLOT(setValue(int)));
connect(ui->spinBox,SIGNAL(valueChanged(int)),ui->horizontalSlider,SLOT(setValue(int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,tr("Load Lit Image"),".",tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
image_Lit = cv::imread(fileName.toAscii().data());
cv::namedWindow("Lit Image");
cv::imshow("Lit Image", image_Lit);
}
void MainWindow::on_pushButton_2_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,tr("Load Lit Image"),".",tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
image_Idl = cv::imread(fileName.toAscii().data());
cv::namedWindow("Ideal Lit");
cv::imshow("Ideal Lit", image_Idl);
}
void MainWindow::on_pushButton_3_clicked()
{
//Converstions
//Convert Lit to gray
cv::cvtColor(image_Lit, image_Lit_G,CV_RGB2GRAY);
//Convert Ideal gray
cv::cvtColor(image_Idl, image_Idl_G,CV_RGB2GRAY);
//Threshold the Images to a designated value
// Lit
threshHold = ui->horizontalSlider->value();
cv::threshold(image_Lit_G,image_Lit_G, threshHold,255,cv::THRESH_BINARY);
cv::namedWindow("Gray Scaled Image");
cv::imshow("Gray Scaled Image", image_Lit_G);
}
Error from the compiler:
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file C:\OpenCV\modules\imgproc\src\color.cpp, line 2834
The program has unexpectedly finished.
Pop up window error:
Microsoft Visual C++
This application as requested to terminate in an unusual way.
#include "iostream"
#include "cv.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("C:\\lena.jpg");
cvtColor(image,image,CV_RGB2GRAY);
imshow("test",image);
waitKey();
return 0;
}
above code(console app in Qt..) is working....it shows a gray image...try to include the cv.h file...
I have recompiled the above program after updating my windows7 machine and astonishing it worked!
Its really weird... I didn't made any changes to the program (at least I can't remenber doing anythin significantly different) but after reinstalling comodo firewal it worked.....
Thanks guys, for your help.