Is there any way to work with camera with QCamera class in Nokia N9 (Meego 1.2 Harmattan) or I should use another one?
Here's my problem: simple application that works fine on Nokia C6-01 (Symbian Anna) doesn't do anything useful on N9.
Here're code snipets:
testmobile.pro
<...>
CONFIG += mobility
MOBILITY += multimedia
LIBS += -lQtMultimediaKit
<...>
mainwindow.h
class MainWindow : public QWidget
{
Q_OBJECT
<...>
private:
QCamera* camera_;
QGraphicsView *view;
QGraphicsVideoItem *videoItem;
QGraphicsScene *scene;
<...>
}
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
<...>
camera_ = new QCamera;
view = new QGraphicsView(this);
scene = new QGraphicsScene(view);
videoItem = new QGraphicsVideoItem;
view->setScene(scene);
scene->addItem(videoItem);
QVBoxLayout *lay = new QVBoxLayout(this);
lay->addWidget(view);
this->setLayout(lay);
view->show();
camera_->setViewfinder(videoItem);
camera_->start();
}
<...>
So after MainWindow object is constructed and shown we'll se a simple viewfinder on Nokia C6-01 and black screen on Nokia N9.
Any ideas?
I found solution!
It was security problem. As I found - Meego has analogue of "capabilities" of Symbian. It's called AEGIS security tokens.
So, to request a permission to work with camera (or any other) you should add your_application_name.agis file into the "qtc_packaging/debian_harmattan" folder of your project.
In my case this file consisted of:
<aegis>
<request>
<credential name="GRP::video"/>
<credential name="GRP::pulse-access"/>
<for path="/opt/testmobile/bin/testmobile"/>
</request>
</aegis>
So permissons are defined in the "name" property of "credential" tag and "for path" tag defines package to perform these permissions with.
More information can be found here
Related
I have a very simple test project under Windows 7 with the following code only on the main window:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSettings>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings settings("./conf.ini");
settings.setValue("testconf", 123);
settings.sync();
}
MainWindow::~MainWindow()
{
delete ui;
}
I just made a project from scratch and the MainWindow is empty. For reference, I add the .pro content, though it should not be relevant:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qsettingstest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I tried different paths for the settings file, using QStandardPaths::writableLocation(QStandardPaths::DataLocation), existing directories e.g. "c:\mydir". I tried also replacing QSettings settings("./conf.ini"); with QSettings *psettings = new QSettings("./conf.ini");, call sync or not call it, but:
The file is not created or modified (in case I create it manually before). Why?
You use 1 QString constructor for QSettings. This will set the Organization Name, not the file name (see https://doc.qt.io/qt-5/qsettings.html#QSettings, application name is defaulted to an empty QString).
This will store/read the settings from the windows registry. Check for a ./conf.ini key there
You want to use the QSetting constructor taking a filename and a format (see https://doc.qt.io/qt-5/qsettings.html#QSettings-3):
QSettings settings("./conf.ini", QSettings::IniFormat);
I'm using QSystemTrayIcon to display notification in Windows 10.
Along with the notification, the application name is also displayed.
The problem here is the app name is displayed along with the extension(.exe).
How can the extension(.exe) be removed from the notification?
Try adding this line to your .pro file:
QMAKE_TARGET_DESCRIPTION = "Whatever"
It should change the process name (both in the notifications and in the task manager) to "Whatever".
More variables like this can be found here: Qmake Variables Documentation
Note from the documentation:
This is only utilized if the VERSION or RC_ICONS variable is set and the RC_FILE and RES_FILE variables are not set.
Step-by-step instructions for creating a test application
Create Qt Widgets Application project, containing a QWidget based widget
Create images directory in the project folder, put an icon file into it (for this example let it be icon.ico)
Add a resource file to the project
To that resource file add prefix /, then "Add Files", selecting ./images/icon.ico
In main.cpp change the code to following:
#include "widget.h"
#include <QApplication>
#include <QIcon>
int main(int argc, char *argv[])
{
QCoreApplication::setApplicationName(APP_NAME);
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/images/icon.ico"));
Widget w;
w.setWindowTitle(qApp->applicationName());
w.setWindowIcon(qApp->windowIcon());
w.show();
return a.exec();
}
In widget.cpp change code to following:
#include "widget.h"
#include "ui_widget.h"
#include <QSystemTrayIcon>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(qApp->windowIcon(), this);
trayIcon->show();
connect(trayIcon, &QSystemTrayIcon::activated, [=]() {
trayIcon->showMessage("Title", "Message");
});
}
Widget::~Widget()
{
delete ui;
}
To the bottom of the project (.pro) file add following:
DEFINES += APP_NAME=\\\"AppName\\\"
QMAKE_TARGET_DESCRIPTION = "Whatever"
win32:RC_ICONS += images/icon.ico
Save, run qmake (Build -> Run qmake), rebuild project
Start the application. Now the window title should be "AppName", which came from APP_NAME define, both window and tray icon - icon.ico, and the process name in task manager and notifications - "Whatever". You can make the app display a notification by clicking on the tray icon. Notification should look like this:
I have 4 qml files and one main.cpp to load qml file.
Is it possible for me to create 1 dll file for those 4 qml file.
And use it in different application if so how to do that.
As already said, there is no need for embedding qml files only in a library. But of course you have the right to do all you want, even that. I know at least 2 ways to do that:
1. Create binary resource file
Prepare resource file containing qml files and then compile it:
rcc -binary plugin.qrc -o plugin.rcc
Now you can include this file into your application :
QResource::registerResource("plugin.rcc");
and use it as regular qrc file:
QResource::registerResource(qApp->applicationDirPath() + "/plugin.rcc");
QQuickView *view = new QQuickView();
view->setSource(QUrl("qrc:/qml/myfile.qml"));
Here qml/ is prefix in resource file.
2. Shared libraryAnother way is to create a shared library containing the same resource file. For example your plugin's shared library implements following interface:
interface.h
#ifndef PLUGIN_INTERFACE_H
#define PLUGIN_INTERFACE_H
#include <QString>
#include <QObject>
class PluginInterface
{
public:
virtual ~PluginInterface() {}
virtual QByteArray getQML(const QString &name) = 0;
};
#define PluginInterface_iid "org.qt-project.PluginInterface"
Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid)
#endif
and its implementation is:
QByteArray PluginImpl::getQML(const QString &name)
{
QFile file(":/qml/" + name);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QByteArray();
return file.readAll();
}
Now, in your application you load your plugin and get its resource as a string:
QDir pluginsDir(qApp->applicationDirPath());
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath("plugin.dll"));
QObject *plugin = pluginLoader.instance();
if (plugin) {
PluginInterface *pluginInstance = qobject_cast<PluginInterface *>(plugin);
if (pluginInstance) {
QByteArray content = pluginInstance->getQML("file1.qml");
QQuickView *view = new QQuickView();
QQmlComponent component(view->engine());
component.setData(content, QUrl());
QQuickItem *childItem = qobject_cast<QQuickItem*>(component.create());
childItem->setParentItem(view->contentItem());
QWidget *container = QWidget::createWindowContainer(view);
container->setFocusPolicy(Qt::TabFocus);
ui->verticalLayout->addWidget(container);
}
}
But pay attention, when you deploy your application you anyway have to copy all qml system files, like #QTPATH/qml/QtQml, #QTPATH/qml/QtQuick.2, #QTPATH/qml/QtQuick.2 etc.
Links:
Resource compiler
Same theme
Plugin example
Have a look at the documentation for QML Modules
There are options for QML-only modules, C++ only and mixed mode.
I have 4 qml files and one main.cpp to load qml file.
Is it possible for me to create 1 dll file for those 4 qml file.
And use it in different application if so how to do that.
As already said, there is no need for embedding qml files only in a library. But of course you have the right to do all you want, even that. I know at least 2 ways to do that:
1. Create binary resource file
Prepare resource file containing qml files and then compile it:
rcc -binary plugin.qrc -o plugin.rcc
Now you can include this file into your application :
QResource::registerResource("plugin.rcc");
and use it as regular qrc file:
QResource::registerResource(qApp->applicationDirPath() + "/plugin.rcc");
QQuickView *view = new QQuickView();
view->setSource(QUrl("qrc:/qml/myfile.qml"));
Here qml/ is prefix in resource file.
2. Shared libraryAnother way is to create a shared library containing the same resource file. For example your plugin's shared library implements following interface:
interface.h
#ifndef PLUGIN_INTERFACE_H
#define PLUGIN_INTERFACE_H
#include <QString>
#include <QObject>
class PluginInterface
{
public:
virtual ~PluginInterface() {}
virtual QByteArray getQML(const QString &name) = 0;
};
#define PluginInterface_iid "org.qt-project.PluginInterface"
Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid)
#endif
and its implementation is:
QByteArray PluginImpl::getQML(const QString &name)
{
QFile file(":/qml/" + name);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QByteArray();
return file.readAll();
}
Now, in your application you load your plugin and get its resource as a string:
QDir pluginsDir(qApp->applicationDirPath());
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath("plugin.dll"));
QObject *plugin = pluginLoader.instance();
if (plugin) {
PluginInterface *pluginInstance = qobject_cast<PluginInterface *>(plugin);
if (pluginInstance) {
QByteArray content = pluginInstance->getQML("file1.qml");
QQuickView *view = new QQuickView();
QQmlComponent component(view->engine());
component.setData(content, QUrl());
QQuickItem *childItem = qobject_cast<QQuickItem*>(component.create());
childItem->setParentItem(view->contentItem());
QWidget *container = QWidget::createWindowContainer(view);
container->setFocusPolicy(Qt::TabFocus);
ui->verticalLayout->addWidget(container);
}
}
But pay attention, when you deploy your application you anyway have to copy all qml system files, like #QTPATH/qml/QtQml, #QTPATH/qml/QtQuick.2, #QTPATH/qml/QtQuick.2 etc.
Links:
Resource compiler
Same theme
Plugin example
Have a look at the documentation for QML Modules
There are options for QML-only modules, C++ only and mixed mode.
Can anyone tell me how to play video from phone memory??
EDITED :i have use this code for video Playing...
include "playvideo.h"
include "ui_playvideo.h"
include QFileDialog
include phonon/backendcapabilities.h
include phonon/videoplayer
include "mainwindow.h"
PlayVideo::PlayVideo(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::PlayVideo)
{
ui->setupUi(this);
videoPlay();
}
void PlayVideo::videoPlay()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), QDir::homePath());
Phonon::VideoPlayer *player = new Phonon::VideoPlayer(Phonon::VideoCategory,ui->graphicsView );
connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
player->play(fileName);
}
but it gives me error:
undefined reference to -> Phonon::VideoPlayer(Phonon::VideoCategory,QWidget*)
undefined reference to -> Phonon::VideoPlayer(Phonon::Mediasource const&)
Any idea?
Thanks..
Use either Phonon or QtMultimediaKit APIs.
For Phonon, there is a demo application in the Qt source tree (demos/qmediaplayer).
QtMultimediaKit is part of the QtMobility project, so in order to use it you require both Qt and QtMobility to be installed (in your SDK, and on the target device). There is a demo application in the QtMobility source tree (demos/mediaplayer).