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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers
Accepted Solution

Clipboard

I would like to set a QML Button to copy text from my QML TextArea but Qclipboard is not supported which means it has to be done in C++

 

What i'm not understanding is how to tell my C++ clipboard that i want the text from QML TextArea when the button is clicked

Highlighted
Developer
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: Clipboard

[ Edited ]

One way to achieve this: 1. in c++, you can set any object as context into the qml, e.g.

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("myObject", objectOfSomeClass);

 Then in the class that is set, you can define Q_INVOKABLE methods, You can do anything you want (including put the text into clipboard) in the implementation. e.g.

Q_INVOKABLE void myButtonClicked(QString text);

 Finally, you can use java script in QML to trigger the "myButtonClicked()", e.g.

Button {
    text: qsTr("Login")
    onClicked: {
        myObject.myButtonClicked(myTextArea.text);
    }
}

 

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Clipboard

[ Edited ]

something i'm not getting is 

 

void MyAppName::copyButtonClicked(QString text)
{

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

 I've managed to make it clear the clipboard after some playing around with what you gave me (thanks alot btw) the only other thing I don't get is how do i make it get the text from myTextArea i assume that's what QString text is but when this is run my copy button only clears the text leading me to belive i havent properly conneted it to the text area... i'll put everything i have below

 

set object into context

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

 set as public under myappname();

Q_INVOKABLE void copyButtonClicked(QString text);

 

 

Button {
 onClicked: {
      clipboard.copyButtonClicked(myTextArea.text);
   }
}

 do i have to declare myTextArea like i did the clipboard & button in c++ for it to copy the text from it

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Clipboard

Where and how is your text area defined? Does it have an ID of myTextArea?

Are you setting the context property before creating the rootobject? (its necessary). You have myButtonClicked and copyButtonClicked, which one is it trying to call?
Like all of my posts
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Clipboard

[ Edited ]

mybuttonclicked was typo**

textArea is defined in QML, it has an id & an objectName (i've tried setting each as myTextArea)

the "clipboard" context property was set before the root object
it appears everything works except inputing text from myTextArea
because when the copy button is pressed the clipboard is cleared but no text is inserted

 

... dont know if it matters but rootobject is appPage, there is also something already using it and another context property set however everythings working except insert

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Clipboard

Have you put a break point in copyButtonClicked to confirm that you actually have text coming in there? Or a breakpoint?
Like all of my posts
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Clipboard

haven't debugged it, only ran (which does everything except insert text)... doing that it gets stuck on the line after int main in main.cpp

 

clipboard.copyButtonClicked(myTextArea.text);


 i noticed i get a little info to the side because of clipboard, says unknown symbol 

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Clipboard

[ Edited ]

Sorry about all that earlier... i re-wrote it all like below and it still doesnt insert any text, yet clears clipboard text I don't see what i've done wrong

 

set context

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("app", this);

 from header

Q_INVOKABLE

    void copyButtonClicked(QString text);

 the "logic" & problem area

void Tumblr::copyButtonClicked(QString text)
{

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

}

 everything until clipboard.insert(); works like a charm, clipboard.insert("not sure what to do here"); does nothing.....

 

what i'm not understanding is how i'm telling it what text to insert from where since as/is doesnt work

 

button

onClicked: {
                app.copyButtonClicked(in1.text);
            }

 

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Clipboard

Any pointers, tips, suggestions?  from other examples i followed it "should" work yet it still doesnt

Developer
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: Clipboard

I would suggest to debug (either step by step or just print debug info ) to see if the text passed in copyButtonClicked actually contains the text. This will narrow down the issue.