I am doing the NFC project. In this I need to detect the tag and read the tag contents from the NFC tag and i need to send the tag id to the PHP server. From the server side i will get the response as {tagId&tagcontent}. After this i need to extract the tagId and tagcontents. Till this i have finished and working fine. Now my problem is to pass the value to another class. As soon as i get the SUCCESS response from server i need to pass the extracted values to another class. How can i do that. I am new to Qt programming. Please help me.
-
whathave you done till now. Show us some code. – krammer Nov 21 '11 at 05:25
-
I need to pass the QStringList to another class void ScanTag::parseResponse(QString response) { QStringList item = response.split('&'); QString tagId = item[0]; item.removeAt(0); QString buildingId = item[0]; item.removeAt(0); qDebug()<
– sachi Nov 21 '11 at 05:27 -
Please post the code in your question, using the code formatting button **{}**, as it is unreadable in a comment. Thanks. – Clare Macrae Nov 21 '11 at 08:05
1 Answers
You can pass the parameters as key value pairs i.e. use a QHash or a QVector for this purpose.
Moreover, if you want the information ot be too specific, you can define a custom C++ class, containing values for the response fields and pass the reference from your 1st class to the other class.
Parameter passing in Qt is similar to C++.
Your QStringList, QVector or QHash all are just classes. You can pass objects of these class as any other custom class.
For example:
In your target class (say T):
void getResponseHeader(QHash<QString,QString> x);
In your calling class(say C):
T *t = new T(); //or whatever instance you have
t->getResponseHeader(myParsedResponse);
More specifically, you can pass parameters inC++ either by value or by reference. For passing objects, it is better to pass them via reference.
Passing by value means that a copy of the object is made on the callee’s stack and altering the object means altering a local copy so the caller’s object is unchanged when the function returns. Passing by reference means that the address of the object is send (a reference holds an address but behaves like an object) so that the callee can directly alter the original object.
Have a look at this thread for What's the difference between passing by reference vs. passing by value?
A nice explanation with examples is provided on codeforum at http://www.codeguru.com/forum/showthread.php?t=343473
-
I am very new to this Qt and C++ field. Before i was working on Android. I am not much aware of passing those values . Basically i have a problem for passing values from one class to another. If you don't mind can you teach me. please. – sachi Nov 21 '11 at 05:32
-
it would be better if you could show us the exact code and what you have tried till now. Parameter passing is not very different from Java/Android, so you may be stuck in some other place – krammer Nov 21 '11 at 06:35
-
-
it would be better if you edit your question to add the relevant snippets from the code and the errors you are facing – krammer Nov 21 '11 at 06:43