I am looking for a best way to implement a video player application in QML. Almost all QML examples are reading files from filesystem or web:
MediaPlayer {
id: mediaplayer
source: "groovy_video.mp4"
}
VideoOutput {
anchors: parent.fill
source: mediaplayer
}
I want to specify my own source for MediaPlayer - a C++ QObject derived class, that has an interface similar to QIODevice. That would be perfect for my needs. I need to preload video in parts and also to cache it for later use.
Is there an easy solution for my needs?
(I am using Qt 5.2)
Generally speaking you should be able to override any URL that is loaded by QML. The Qt 4 docs are a bit more explicit about this than Qt 5:
https://doc.qt.io/qt-4.8/qdeclarativenetwork.html
But the same should be similar for Qt 5:
http://doc.qt.io/qt-5/qqmlnetworkaccessmanagerfactory.html
e.g. you should be able to use a specific url schema for a custom source magic+videos://.... for your custom source.
Worst case scenario you have to inherit (and override some methods) from QNetworkAccessManager and QNetworkReply (which inherits from QIODevice).
I have not played with this since qt4 but I assume a good starting point would be this:
http://doc.qt.io/qt-5/qtqml-networkaccessmanagerfactory-example.html
I'm a bit outdated on this kind of stuff, but hopefully this helps.
Related
As per https://doc.qt.io/qtcreator/qtquick-placeholder-data.html#creating-dummy-context I want to add a dummy context to my QT 5.15.2 project. The webpage mentioned creating a qml file with the following content:
import QtQuick 2.0
import QmlDesigner 2.0 // this is where the error is indicated: qml module not found (qml designer)
DummyContextObject {
parent: Item {
width: 640
height: 300
}
}
Apparently the QmlDesigner module is unknown. I don't know how to solve this.
The qml code model does not know anything about the existence of that type. So it is correct if it shows that to you.
In detail, that object only exists if the backend process (qmlpuppet or in documentation called emulation layer) renders stuff for the form view in the designer.
But in the current implementation, the qml code model does not know anything about added objects when the emulation layer is running.
I would create a bug report at https://bugreports.qt.io/ about that issue. So the qml code model needs to know about that type somehow.
To make sure that the feature works in the design mode please make sure you are following the help for example there is no qmldesigner 2.0 version only 1.0 exists.
Explanation in the puppet the object is registered with:
qmlRegisterType("QmlDesigner", 1, 0, "DummyContextObject");
see https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp#n184
Also, the file and folder structure is importent.
In my project, there is a language page with four language options. If we change them, entire application language and some images changes. My problem is is there any signal/ callback to switch resources as like in Android or any some other mechanism we should follow for this QML?
To do what you need, first, get familiar with official documentation on Internationalization and Localization with Qt Quick.
Next you need to wrap all strings that should be translated into qsTr. Then, here is simplified code of switching languages:
void Settings::switchToLanguage(const QString &language)
{
if (!m_translator.isEmpty())
QCoreApplication::removeTranslator(&m_translator);
m_translator.load(QStringLiteral(":/language_") + language));
QCoreApplication::installTranslator(&m_translator));
m_engine->retranslate();
}
According to article New in Qt 5.10: Dynamic Language Change in QML.
I have this application where I display content together with a video file. The video files are either in image/jpeg (MJPG format according to vlc) or video/x-h264 format.
To do this, I use a mediasource combined with a video output element to display the video. This is working perfectly when using h264. However, this is not working at all with the mjpg video files.
But I have no idea how to do this. I have read up on libraries using either ffmpeg or vlc, but I can't seem to find libraries to use in combination with QML elements, only with regular QWidgets.
Here is some (stripped down) relevant code, it is really simple and I would prefer to keep it simple. So ideally I am just looking for a way to get a codec into the project or something like that.
property string videoLocation
FileDialog {
id: videoFileDialog
onAccepted: {
videoLocation = fileUrl
}
}
MediaPlayer {
id: mediaplayer
source: videoLocation
autoPlay: false
}
VideoOutput {
id: videoOutput
source: mediaplayer
}
Maybe relevant:
my system is ubuntu 13.04 and I use qt 5.3.
Thx in advance
EDIT: I have figured out the problem I think: The stream is recorded using gstreamer > 1.0. For some reason it won't play back in 0.10. If I record using the same settings, but with gstreamer 0.10, everything is fine and my application works (though this option is not feasible, I really need to capture using > 1)
Here is the code I am using to capture the stream to a file:
gst-launch-0.10 v4l2src device=/dev/cam1 ! image/jpeg,width=320,height=240,framerate=30/1 ! matroskamux ! filesink location=videotest.mkv
Any suggestions for a setting that is compatible between new and old gstreamer?
On *nix platforms, QtMultimedia uses GStreamer as its backend. On GStreamer's website it appears that JPEG is a supported format (and one would assume that includes motion jpeg.)
Check your package manager to make sure you have all of GStreamer's plugins installed. There's at least three different packages of GStreamer plugins on Ubuntu.
So I fixed it by using an avi container instead of a matroska container. No idea why it works now and not with matroska. I can honestly only think this has to be a bug somewhere.
When you place the mouse pointer over any Qt function/class it shows a pop-up with short description of what it does, taken from the docs in the comment above the function/class.
For my functions/classes I have documentation in the doxygen format:
/**
Returns foo
*/
QString getFoo() {
return "foo";
}
When this function is used, I want to view the same type of pop-up with my docs when the mouse pointer is over the function name.
Is it possible to do that with Qt Creator?
Unfortunately it's not possible for Qt Creator (as of the recently release 2.4) to pick up the tags on-the-fly. However, what might work is to let doxygen run, and tell it to create qch files. If you register the created qch file, you should get mouse-over and even a proper help file. See http://www.ogre3d.org/tikiwiki/Integrating+API+documentation+into+Qt+Creator+Help for how Ogre3D does it. YMMV if that's worth it for a fast-changing project. It's certainly a good idea for a (semi-)stable library.
Relevant bug report: https://bugreports.qt.io/browse/QTCREATORBUG-4557
Qt Creator requires the generated docs to have some special markers in order to retrieve the tooltip text. I couldn't find a way to insert these markers with Doxygen so I've created a simple script to do it:
https://github.com/mmmarcos/doxygen2qtcreator
It's not bulletproof but it allows us to integrate our classes and methods briefs into Qt Creator tooltips.
I am trying to develop a plug-in for QtWebkit. But I am not able to find how to develop a plugin for QtWebKit, hopefully one that can be invoked by JavaScript. Does anyone know of any tutorials or documents that explain how to do this?
Webkit has been intregated into Qt and this integrated package is called QtWebkit. They have provided new method for for plugin creation.
-Regards, Vivek Gupta
The simple answer is to write a subclass of QWebPage and set this on your webview. Then you can show your own HTML page and react to the appropriate object tag in the createPlugin method;
protected:
QObject* createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues)
{
if (classid=="lineedit") {
QLineEdit *lineedit = new QLineEdit;
return lineedit;
}
return 0;
}
and show something like the following HTML;
<object type="application/x-qt-plugin" classid="lineedit" id="lineedit">
can't load plugin
</object>
Remember you need to turn on plugins, and possibly also JavaScript if you want more advanced functionality in the QWebSettings
To have more advanced functionality, you should use a QWebPluginFactory
Actually Webkit has been intregated in Qt and this intregated package is called QtWebkit.
And they have provided new method for for plugin creation.I just need a link or steps for creating a plugin in QtWebkit and that plugin should be invoked by java script.
Regards
Vivek Gupta
Introduction to WebKit Plug-in Programming Topics is for WebKit, is QtWebKit that special?
To expose the object to Javascript, use
this->mainFrame()->addToJavaScriptWindowObject("lineedit", this);
where lineedit is the name that can be used to access the object from javascript
Qt properties will be exposed as JavaScript properties and slots as JavaScript methods.
(see http://doc.qt.io/archives/qt-4.7/qwebframe.html#addToJavaScriptWindowObject)