QDesktopServices backend on linux? - qt

What is used to open urls with QDesktopServices::openUrl(...)?
xdg-open, kopen, selmademachanism or a mix of them? I ask because it fails on a scheme where xdg-open does not.
Edit: okay its getting even more curious: The missing scheme works in debug mode, but not in release mode...
Example code:
#include <QApplication>
#include <QDesktopServices>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDesktopServices::openUrl(QUrl("tg://resolve?domain=imagebot"));
}

Related

FFmpeg on Qt Creator

I have got FFmpeg compiled using MSYS2. I have a strange issue that appeared only recently.the app crashes.
This is my main file:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
extern "C" {
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
}
int main(int argc, char *argv[])
{
//qDebug() << av_version_info();
// avdevice_register_all();
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
The program runs but crashes if I call 'avdevice_register_all()' and others FFmpeg functions,but only call 'av_version_info()' is runs, not crashes.
I don't really know how to solve this?
I have already tried to use google solving the problem,but no result.

Qt - Creating PDF file

I want to create a PDF-file in Qt console application. But file size of created file is 0B and I can't open it.
The same code in GUI application works. Where is the difference between code in console and gui application? What should I do to make the code working in console application?
Thanks for help in advance!
#include <QCoreApplication>
#include <QPrinter>
#include <QTextDocument>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString html = "<h1>Hi!</h1>";
QTextDocument document;
document.setHtml(html);
QPrinter printer(QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("test.pdf");
document.print(&printer);
return a.exec();
}
Here it's working.
#include <QApplication>
#include <QPrinter>
#include <QTextDocument>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString html = "<h1>Hi!</h1>";
QTextDocument document;
document.setHtml(html);
QPrinter printer(QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("test.pdf");
document.print(&printer);
return a.exec();
}
so it looks like you have just to change the QCoreApplication by QApplication.

Setting LocalStorage Location via setOfflineStoragePath

I'm trying to set the LocalStorage location (sqlite db) for my QML application but once i rebuild and run the application i still can't see the subfolder, INI file and the sqlite DB created on the desired location (in a subfolder within the resources folder). Here is what's in my main file.
Appreciate any one could pint what's I'm doing wrong here?
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QString>
#include <QDebug>
#include <QDir>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
//engine.setOfflineStoragePath("qrc:/");
auto offlineStoragePath = QUrl::fromLocalFile(engine.offlineStoragePath());
engine.rootContext()->setContextProperty("offlineStoragePath", offlineStoragePath);
QString customPath = "qrc:/OffLineStorage";
QDir dir;
if(dir.mkpath(QString(customPath))){
qDebug() << "Default path >> "+engine.offlineStoragePath();
engine.setOfflineStoragePath(QString(customPath));
qDebug() << "New path >> "+engine.offlineStoragePath();
}
return app.exec();
}
By looking at the code snippet in your question, everything looks fine.
Anyway, you should verify if the following line actually returns true as you expect:
dir.mkpath(QString(customPath)
If no, the body of the if statement isn't executed in any case, thus setOfflineStoragePath is never invoked.
As a hint, using qrc:/OffLineStorage as a path for your storage doesn't seem to be a good idea. I'm not sure it will work once in the production environment (to be checked, it sounds strange, but it could work).
Try use engine.setOfflineStoragePath before engine.load.
Using qrc:/OffLineStorage as a path for your storage doesn't seem to
be a good idea. I'm not sure it will work once in the production
environment
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QString>
#include <QDebug>
#include <QDir>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QString customPath = "qrc:/OffLineStorage";
QDir dir;
if(dir.mkpath(QString(customPath))){
qDebug() << "Default path >> "+engine.offlineStoragePath();
engine.setOfflineStoragePath(QString(customPath));
qDebug() << "New path >> "+engine.offlineStoragePath();
}
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
engine.clearComponentCache();
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}

Error Occured while designing Dialog in Qt

The program name is GoToCell in the form I created a label and two push buttons and I wrote the code in main.cpp as follows:
#include <QtGui/QApplication>
#include<QDialog>
#include "ui_GoToCell.h"
#include "GoToCell.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Ui::GoToCell ui;
QDialog *dialog=new QDialog;
ui.setupUi(dialog);
dialog->show();
return a.exec();
}
While running it I'm getting the following errors:
GoToCell is not a member of ui
What should I do?
I think you have misspelled object name in objectName property in the GoToCell.ui form.
Change it to GoToCell. It will then execute.

Undefined reference to fp_init() Using fprint in Qt

I am trying to use the libfprint in my Qt application
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libfprint/fprint.h>
int main(int argc, char *argv[])
{
int r = 1;
struct fp_dscv_dev *ddev;
struct fp_dscv_dev **discovered_devs;
struct fp_dev *dev;
struct fp_print_data *data;
r = fp_init();
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Compiling throws this error
/concept/main.cpp:31: undefined reference to `fp_init()'
I have been battling with this for a while now. Any idea what I can do to get past this point? Thanks in advance!
It's a problem with your linker - it cannot find necessary libraries. Did you pass necessary linker switches (something like -lfoo) instructing it to link with library you are trying to use?

Resources