简体   繁体   English

如何在iOS的QT / QML中使用剪贴板

[英]How to use Clipboard in QT/QML on iOS

QML code to copy text to system clipboard QML代码将文本复制到系统剪贴板

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. 此剪辑/过去的代码在Windows和OSX中可以正常工作。 Is weird on iOS 在iOS上很奇怪

Question: Is there some encoding conversion happening here? 问题:这里是否发生了一些编码转换? from "testclip" to "氀漀甀渀最攀" ? 从“ testclip”到“氀漀甀渀最攀”?

Note: QT 5.7 注意: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?? 几乎就像ios剪贴板和我的应用程序之间正在发生某种形式的SSL一样?

Thanks 谢谢

I was facing a similar issue in my QtQuick app using Qt 5.7.1 on iOS. 在iOS上使用Qt 5.7.1的QtQuick应用程序中,我遇到了类似的问题。

Seems like the QClipboard implementation in Qt 5.7.1 had a bug. 好像Qt 5.7.1中的QClipboard实现有一个错误。 I could get the copy/paste working using the following code to directly set text to the iOS paste board. 我可以使用以下代码将复制/粘贴工作直接设置为iOS粘贴板。

#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 供参考: https : //bugreports.qt.io/browse/QTBUG-56229

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM