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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
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:

Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
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);

 

 

 

 

 

Please use plain text.
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
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.

Please use plain text.
Trusted Contributor
slashkyle
Posts: 166
Registered: ‎10-16-2012
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

Please use plain text.
Developer
HorizonXP
Posts: 131
Registered: ‎03-28-2011
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!
Please use plain text.
Contributor
caco3
Posts: 14
Registered: ‎11-24-2012
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)

Please use plain text.
Developer
HorizonXP
Posts: 131
Registered: ‎03-28-2011
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!
Please use plain text.