[SailfishDevel] System clipboard and QApplication

J-P Nurmi jpnurmi at gmail.com
Fri Apr 25 21:08:41 UTC 2014


Hi,

See https://sailfishos.org/sailfish-silica/qml-sailfishsilica-clipboard.html

--
J-P Nurmi

On 25 Apr 2014, at 19:57, Samuli Silvius <samuli.silvius at gmail.com> wrote:

> Thanks a lot, the QML trick works great!
> 
> -Samuli
> 
> 
> 2014-04-24 9:16 GMT+03:00 Andrey Kozhevnikov <coderusinbox at gmail.com>:
> use QGuiApplication or QCoreApplication. QApplication itself is deprecated.
> 
> There is also dark side hack for using QML clipboard:
> 
>     TextEdit {
>         id: clipboard
>         visible: false
>         function setClipboard(value) {
>             text = value
>             selectAll()
>             copy()
>         }
>         function getClipboard() {
>             text = ""
>             paste()
>             return text
>         }
>     }
> 
> 24.04.2014 12:03, Samuli Silvius пишет:
>> Hi,
>> 
>> I use system clipboard in QML app with small C++ adapter
>> 
>> #ifndef QMLCLIPBOARDADAPTER_H
>> #define QMLCLIPBOARDADAPTER_H
>> #include <QApplication>
>> #include <QClipboard>
>> #include <QObject>
>> class QmlClipboardAdapter : public QObject
>> {
>>     Q_OBJECT
>> public:
>>     explicit QmlClipboardAdapter(QObject *parent = 0) : QObject(parent) {
>>         clipboard = QApplication::clipboard();
>>     }
>>     Q_INVOKABLE void setText(QString text){
>>         clipboard->setText(text, QClipboard::Clipboard);
>>         clipboard->setText(text, QClipboard::Selection);
>>     }
>> private:
>>     QClipboard *clipboard;
>> };
>> #endif // QMLCLIPBOARDADAPTER_H
>> 
>> And it's working fine. But this requires that I have to add 
>> 
>> QT += widgets
>> 
>> to .pro file and seems it's not supported by Jolla Harbour as also Jolla SDK RPM validation gives me an errors. I have updated the SDK to the latest.
>> 
>> ERROR [/usr/share/harbour-jolla2gether/qml/harbour-jolla2gether.qml] Import 'QmlClipboardAdapter 1.0' is not allowed
>> ERROR [/usr/bin/harbour-jolla2gether] Cannot link to shared library: libQt5Widgets.so.5
>> 
>> 
>> Is there are way around this?
>> 
>> Br
>> -Samuli
>> 
>> 
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>> 
> 
> 
> _______________________________________________
> SailfishOS.org Devel mailing list
> 
> _______________________________________________
> SailfishOS.org Devel mailing list



More information about the Devel mailing list