Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None

How to access ClipBoard from QML?

[ Edited ]

I would like to copy a text from QML into the clipboard.

It seems QML does not provide a way for this?

 

I only found solutions for C++ (http://supportforums.blackberry.com/t5/Cascades-Development/Clipboard/m-p/1962669 )

But since I am not using C++, this is not an option :smileysad:

Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: How to access ClipBoard from QML?

[ Edited ]

Unfortunately there are going to be things that will require some C++ however not all is lost, there's 2 ways of doing that, the NDK way or the cascades way which is the link you posted & will work even if you're sticking mainly to QML... 

 

 

in you're .cpp

void AppName::copyText(QByteArray text)
{

	 Clipboard clipboard;
	 clipboard.clear();
	 clipboard.insert("text/plain", text);
}

in you're .hpp

public:
    
    Q_INVOKABLE
    void copyText(QByteArray text);

 to access via QML stick this in a buttons onClicked() or something similar

 

AppName.copyText(myTextArea.text);

 AppName is your "context property" which should be set in your .cpp file such as 

qml->setContextProperty("AppName", this);

 

 

 

 

 

Contributor
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None

Re: How to access ClipBoard from QML?

Thank you for your reply!

 

So there is no way without using C++?

I am using QML together with Python (http://blackberry-py.microcode.ca )

I am not planing to switch to C++ just because of the clipboard. I know from other Systems (Nokia N9, Harmattan) that in general it is possible to access the clipboard from QML directly.

 

I now implemented the share functionality. Would be cool if the clipboard also would be added to that as a target.

Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: How to access ClipBoard from QML?

That's the only way I know how to access the clipboard, it should be possible to convert the .cpp portions of that code to python & access it that way

Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: How to access ClipBoard from QML?

caco3, it's your lucky day. I too am using Python + QML, and I ran into this problem. I will write an extension and update the repo. Stay tuned.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Contributor
Posts: 14
Registered: ‎11-24-2012
My Device: none
My Carrier: None

Re: How to access ClipBoard from QML?

That sounds great.

Please let me know when you get it working.

 

How are you using Python?
I am using BBTart (https://twitter.com/search?q=%23BBTart)

Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: How to access ClipBoard from QML?

I'm using BB Tart as well. I just contributed the clipboard class to the repo. peter9477 and I are the lead contributors to the project, him being more lead than I!

 

http://hg.microcode.ca/blackberry-py/commits/93543c2ee178fcfffce74eb9a0f52e96f77297d8


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Developer
Posts: 20
Registered: ‎06-21-2013
My Device: Z10 STL100-3
My Carrier: Personal

Re: How to access ClipBoard from QML?

nice implementation in pure python Horizon!!

Thanks a lot.

Im also using python :smileyhappy:

~namida de as.hita ga mienai~
Developer
Posts: 296
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: How to access ClipBoard from QML?

In case someone else is searching at this place, there are a additional way to access the clipboard.

 

Read the Files in the directory "/var/clipboard/" at the device yourself. :smileyhappy: