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)
Related
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 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.
I have a very simple Qt Application which uses QtWebkit and QWebPage to render webpages. The problem is that it doesn't seem to support popups. For example, in google.com, when I click on "Gmail", a Javascript alert say that my browser has disabled the popups...
And a html file with the following "a" tag: Link works neither.
Can anybody help me?
Thanks.
You need to redefine either QWebPage::createWindow or QWebView::createWindow to create a new QWebPage and/or QWebView.
I develop an app with plugins. Each plugin should have it's own settings window (QDialog type).
If plugin's settings form was included in main project, I'll simply create it with passing main form as parent as said here: http://developer.qt.nokia.com/doc/qt-4.8/qdialog.html#QDialog (and in Google results for this problem).
But when QDialog declared in separated plugin, I think that it's ugly and insecure to pass main form as parent from main app to plugin instance.
Any ideas? Stub QWidget?
I have a small idea. This is different approach but it might work in your case too. As I understand you are trying to create settings manager for you application. You can use QSettings for example and store settings for each plugin in different subgroup. For example you have a main app settings and two other plugins.
[Main App]
key1=val1
key2=val2
[Plugin1]
key1=val1
key2=val2
[Plugin1]
key1=val1
key2=val2
This way you could easily construct a QDialog in your main appication and change/save the settings. In turn the main application notifies plugins via signal that settings have changed and need to be reloaded. This way you encapsulate you main application from your plugins.
update
Thanks for a quick feedback. The approach I proposed is MainApplication centric but it can be redesigned to be decentralized. Since QSettings is application specific your plugins can store their settings in one configuration with main app as before. One modification I would make is the following. You can create a QDialog within your plugin and modify the settings without necessity for main app to be aware of this process.
Ok, I'd just create stub QWidget as suggest earlier:
QWidget *a = new QWidget();
settingsForm = new OpenFolderSettings(a);
...
delete settingsForm;
delete a;
So now dialog doesn't show button on taskbar. Also, no new window appear.
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.