qt5 error occur Poppler::Document* document - c++

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;

Related

Cant load music file with QMediaPlayer

I am creating media player with qt5. Code below works fine ( it open file dialog, load one song and play it after loading) but it can't play some MP3 files. These files are not damaged or something like this, I can open them with other media players. I noticed that the most of them are larger than 20 mB. Please help me if you find the solution.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QDebug>
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&player, &QMediaPlayer::mediaStatusChanged,
this, [&](QMediaPlayer::MediaStatus status){
if(status == QMediaPlayer::LoadedMedia) //play if loaded
player.play();
});
connect(&player , QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), // notify about errors
[=](QMediaPlayer::Error error){
if (error==QMediaPlayer::ResourceError)
qDebug("resource");
if (error==QMediaPlayer::FormatError)
qDebug("format");
if (error==QMediaPlayer::AccessDeniedError)
qDebug("acces");
if (error==QMediaPlayer::ServiceMissingError)
qDebug("service");
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{ QString file= QFileDialog::getOpenFileName(); //select file
player.setMedia(QUrl::fromLocalFile(file)); // load
}

out of memory. Error opening database. sqlite3 and UWP kit in Qt

I made a very simple program to open a sqlite3 database and create a sample table in it. I wrote this code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlQuery>
#include <QSqlError>
#include <QMessageBox>
#include <QStandardPaths>
#include <QFile>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QFile file(QStandardPaths::displayName(QStandardPaths::AppDataLocation) + "/library.db");
if(file.open(QFile::ReadWrite))
QMessageBox::information(this, "", "Successfully created database");
db.setDatabaseName(file.fileName());
db.setHostName("Test");
if(db.open())
{
QSqlQuery query;
if(!query.exec("create table if not exists test(name text not null)"))
QMessageBox::critical(this, "Oops!", "Unable to create table: " + query.lastError().text());
}
else
QMessageBox::critical(this, "Oops!", "Unable to open database: " + db.lastError().text());
}
MainWindow::~MainWindow()
{
delete ui;
}
I tested the code in debug mode (dektop kit) and it worked. I then, tried debug mode in Universal Windows Platform 32 bit kit(64 bit doesn't work either). But this time, although the code compiles fine and the app is deployed too, the database is not created. And it shows the error: "out of memory. Error opening database". Is it something about UWP that I am missing?
I checked the build folder of the project, and NO database was created.
I am using 64-bit windows 10

GUI gets blank while processing

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?

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 play a .wav file using QSound in qt5

I tried using QSound in my project but I am getting an undefined refrence to _imp_ZN6Q:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtMultimedia/QSound>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
ui->setupUi(this);
QSound player;
QSound::play("E:\songs");
}
MainWindow::~MainWindow()
{
delete ui;
}
In your project file (.pro) add
QT += multimedia
QT += multimedia
and add :
#include <QtMultimedia/QSound>
QSound newMessage("sound/newChat.wave");
newMessage.play();