jaybny
jaybny

Reputation: 1028

How to use Clipboard in QT/QML on iOS

QML code to copy text to system clipboard

Item {

TextEdit {
    id: cliphelper
    visible: false
}

Button{
    onClicked: {
        cliphelper.text = "testclip"
        cliphelper.selectAll()
        cliphelper.copy()
    }
}

When i run this and then past into an email, i get this.

氀漀甀渀最攀

This clip/past code works fine in Windows and OSX. Is weird on iOS

Question: Is there some encoding conversion happening here? from "testclip" to "氀漀甀渀最攀" ?

Note: QT 5.7

Also when i paste directly back into my app it comes out fine, but when I clip this again 氀漀甀渀最攀 from another app and then paste it doesn't convert it.

Is almost as if there is some kind of ssl going on between the ios clipboard and my app??

Thanks

Upvotes: 1

Views: 1082

Answers (1)

bugfighter
bugfighter

Reputation: 36

I was facing a similar issue in my QtQuick app using Qt 5.7.1 on iOS.

Seems like the QClipboard implementation in Qt 5.7.1 had a bug. I could get the copy/paste working using the following code to directly set text to the iOS paste board.

#include "ioswrapper.h"
#import <UIKit/UIPasteboard.h>

ioswrapper::ioswrapper(QObject *parent):QObject(parent)
{

}
void ioswrapper::setPasteBoardString(const QString &paste)
{
        UIPasteboard *pb = [UIPasteboard generalPasteboard];
        if (pb) {
                    const char *str = paste.toUtf8().data();
                    NSString *text = [NSString stringWithCString:(const char *)str
                        encoding:(NSStringEncoding)NSUTF8StringEncoding];
                    if (text)
                        pb.string = text;
        }
}

for reference: https://bugreports.qt.io/browse/QTBUG-56229

Upvotes: 2

Related Questions