read value from QVariantist into qml - qt

I am a complete beginner in Qt and have the following problem. I want to access a certain value from my QVariantList in qml. Here is what I tried:
width: typeof(_styleconfiguration.styleMapping["width"])
Unfortunately this call returns me a string. How can I cast it to an Int?
The content of my QVariantList looks like this:
QMap(("activeBackgroundColor", QVariant(QString,
"#FFFFFF"))("activeForegroundColor", QVariant(QString,
"#006381"))("border", QVariant(qlonglong, 1))("borderColor",
QVariant(QString, "#006381"))("height", QVariant(qlonglong,
80))("pressedBackgroundColor", QVariant(QString,
"#E5F4F9"))("pressedForegroundColor", QVariant(QString,
"#35322f"))("radius", QVariant(qlonglong, 10))("shadowColor",
QVariant(QString, "#000000"))("shadowHOffset", QVariant(qlonglong,
20))("shadowVOffset", QVariant(qlonglong, 0))("width",
QVariant(qlonglong, 80)))
Would be happy if someone can help me further.

Related

Add ibanCode to exceptionMessage

I want to add iban code to my OpaCallException, so that I would know specifically which iban code is incorrect.
My code:
FIND FIRST tt_iban_crc_aaa WHERE tt_iban_crc_aaa.iban=tt_fee_request.debtorAccount AND tt_iban_crc_aaa.crc=g-crc NO-LOCK NO-ERROR.
IF NOT AVAILABLE tt_iban_crc_aaa THEN DO:
FIND FIRST aaa WHERE aaa.name=tt_fee_request.debtorAccount AND aaa.crc=g-crc NO-LOCK NO-ERROR.
IF AVAILABLE aaa THEN DO:
CREATE tt_iban_crc_aaa.
ASSIGN
tt_iban_crc_aaa.aaa = aaa.aaa
tt_iban_crc_aaa.crc = aaa.crc
tt_iban_crc_aaa.iban = aaa.name
.
END.
ELSE DO:
UNDO, THROW NEW OpaCallException("iban.invalid", "Iban incorrect", "Provided iban is invalid").
END.
END.
I am having difficult time with progress syntax. I could use some help or tips, thanks!
It looks like you need to use the SUBSTITUTE() function.
Replace "Provided iban is invalid" with SUBSTITUTE ("Provided iban (&1) is invalid", [Whatever field the iban code is in]).
You need to add a property in your OpaCallException class
DEFINE PUBLIC PROPERTY IbanCode AS CHARACTER NO-UNDO
GET.
PRIVATE SET .
Then add a constructor like this:
CONSTRUCTOR PUBLIC OpaCallException (pcIbanCode AS CHARACTER, /* add additional parameters */):
ASSIGN THIS-OBJECT:IbanCode = pcIbanCode.
SUPER (SUBSTITUTE ("Error with IBAN Code: &1", pcIbanCode), 0) .
END CONSTRUCTOR.

Firebase startAt String only takes first character

I have a structure like below under xyz
{
"pushKey000": {
"findKey": "john_1",
"userName": "john",
"topic": 1
},
"pushKey001": {
"findKey": "john_2",
"userName": "john",
"topic": 2
},
"pushKey002": {
"findKey": "joel_1",
"userName": "joel",
"topic": 1
}
}
Now am trying to make a query where I want data of all entries with findKey starting with "john". I tried the following:(Using REST for example)
https://abc.firebaseio.com/xyz.json?orderBy="findKey"&startAt="john"
This gives me all the results including 'joel'. Basically it just uses the first character of startAt, in this case J.
This firebase video fires the same type of query but only searches with just first character.
Is there something wrong that I am doing or is there is any other way to retrieve it using findKey? Thanks a lot for the help in advance
PS: My .indexOn is on findKey and can't change it
There is nothing wrong with your code, there is something wrong with your expectations. (I always wanted to write that as an answer :))
The startAt() function works as a starting point for your query, not a filter. So in your case it will find the first occurance of "john" and return everything from that point forward (Including Joel, Kevin, Tim, etc...).
Unfortunatly there is no direct way to do a query where findKey contains the string "john". But luckely there is a (partial) workaround using endAt().
You query will look like this:
orderBy="findKey"&startAt="john"&endAt="john\uf8ff"
Here \uf8ff is the last unicode character (please correct me if I'm wrong).
With this you can query for values that start with "john" like "johnnie", "johnn", "john". But not "1john" or "johm" or "joel".

Encoding issues with Disqus API results (2 Unicode characters which should be interpreted as one)

I have got a Qt application which receive strings in JSON objects from the Disqus API:
{ "title": "Swiftkey pr\u0102\u0160dit votre choix d\u2019emoji gr\u0102\u02d8ce au clavier Swiftmoji" }
(there's more but I only write what matters here)
Then I put the title string in a QString:
// Assuming that "reply" is the QNetworkReply * containing the Disqus API response.
QByteArray disqusReply = reply->readAll();
// disqusReply == "{ \"title\": \"Swiftkey pr\u0102\u0160dit votre choix d\u2019emoji\ gr\u0102\u02d8ce au clavier Swiftmoji" }"
QJsonDocument doc = QJsonDocument::fromJson(disqusReply);
QJsonObject obj = doc.object();
QString title = obj["title"].toString();
Later I write it in a QML Text. It should display "Swiftkey prédit votre choix d'emoji grâce au clavier Swiftmoji" but it displays "Swiftkey prĂŠdit votre choix d'emoji grâce au clavier Swiftmoji" instead.
As you can see there are some encoding issues, with two successive Unicode characters which should be interpreted as one character only ("ĂŠ" instead of "é" and "â" instead of "à" here). How can I do (with Qt or QML) to display the right characters? Which encoding conversions I have to perform (with Qt or QML) in order to solve those encoding issues?
Additional informations: the bug occurs on Windows 10 64-bit.
EDIT : you can find the bug here: https://disqus.com/api/3.0/threads/list.json?since=2016-05-18T14%3A08%3A27%2B00%3A00&forum=frandroid&api_key=7o0xSBOEzN2AG6yxcJgeJbeEbACBfGhgnoIRHu7umbifKAvXQpisYKT3KSXF9nPN
Well, I think the problem in double encoding or something else from server side, not from client's. Because your code must be pr\u00e9dit instead of pr\u0102\u0160dit. If you'll use clean_title instead of title of your json-answer you'll get the right string cause it's encode is correct.
UPD:
As I said in comment - there are two replies with same news. Id 4836688567 has wrong encode string. And 4836587900 correct. There are many double variants of news with different encoding.
First:
{
"feed":"https://frandroid.disqus.com/httpwwwfrandroidcomandroidapplications358721_swiftkey_predire_choix_demoji_grace_clavier_swiftmoji/latest.rss",
"identifiers":[],
"dislikes":0,
"likes":0,
"message":"",
"id":"4836688567",
"createdAt":"2016-05-18T09:08:43",
"category":"448171",
"author":"3938134",
"userScore":0,
"isSpam":false,
"signedLink":"http://disq.us/?url=http%3A%2F%2Fwww.frandroid.com%2Fandroid%2Fapplications%2F358721_swiftkey-predire-choix-demoji-grace-clavier-swiftmoji&key=nqCbe6jgfwM-skLyqTf3lg",
"isDeleted":false,
"raw_message":"",
"isClosed":false,
"link":"http://www.frandroid.com/android/applications/358721_swiftkey-predire-choix-demoji-grace-clavier-swiftmoji",
"slug":"httpwwwfrandroidcomandroidapplications358721_swiftkey_predire_choix_demoji_grace_clavier_swiftmoji",
"forum":"frandroid",
"clean_title":"Swiftkey pr\u0102\u0160dit votre choix d\u2019emoji gr\u0102\u02d8ce au clavier Swiftmoji",
"posts":0,
"userSubscription":false,
"title":"Swiftkey pr\u0102\u0160dit votre choix d\u2019emoji gr\u0102\u02d8ce au clavier Swiftmoji",
"highlightedPost":null
}
Second:
{
"feed":"https://frandroid.disqus.com/swiftkey_predit_votre_choix_d8217emoji_grace_au_clavier_swiftmoji/latest.rss",
"identifiers":["358721 http://www.frandroid.com/?p=358721"],
"dislikes":0,
"likes":1,
"message":"",
"id":"4836587900",
"createdAt":"2016-05-18T08:16:30",
"category":"448171",
"author":"3938134",
"userScore":0,
"isSpam":false,
"signedLink":"http://disq.us/?url=http%3A%2F%2Fwww.frandroid.com%2Fandroid%2Fapplications%2Fgoogle-apps%2F358721_swiftkey-predire-choix-demoji-grace-clavier-swiftmoji&key=UU8IrLN_UDXEggF6wHjAYg",
"isDeleted":false,
"raw_message":"",
"isClosed":false,
"link":"http://www.frandroid.com/android/applications/google-apps/358721_swiftkey-predire-choix-demoji-grace-clavier-swiftmoji",
"slug":"swiftkey_predit_votre_choix_d8217emoji_grace_au_clavier_swiftmoji",
"forum":"frandroid",
"clean_title":"Swiftkey pr\u00e9dit votre choix d\u2019emoji gr\u00e2ce au clavier Swiftmoji",
"posts":13,
"userSubscription":false,
"title":"Swiftkey pr\u00e9dit votre choix d’emoji gr\u00e2ce au clavier Swiftmoji",
"highlightedPost":null
}
As you see, difference in url from where news comes. But why some of them encoded wrong - this is a question.
UPD 2:
Or maybe it's RSS bug. Let's take prédit word. In second variant RSS returns xml with content which has been already encoded to é and feed link looks like normal. In first variant RSS returns ĂŠ and its feed link looks like anormal - feel like it takes whole url and do another encode.
Have you tried
QByteArray disqusReply
= QString::fromUtf8(reply->readAll().data()).toLocal8Bit();
? You might prefer delaying this conversion until actually writing the string into the QML text.
QJsonDocument requires UTF-8 encoded strings. Is your document encoded in UTF-8 when you load it?

$firebaseArray move object from index to index

Here I pull a list of transactions and I show them in an ion-list with show-reorder enabled
var ref = fb.child("/members/" + fbAuth.uid + "/accounts/" + $scope.AccountId + "/transactions/");
$scope.transactions = $firebaseArray(ref);
I have the following code to handle sorting
$scope.moveItem = function (transaction, fromIndex, toIndex) {
$scope.transactions.splice(fromIndex, 1);
$scope.transactions.splice(toIndex, 0, transaction);
};
I know I'm approaching this the wrong way from reading the docs here. However, I have not been able to find the way to sort items (transactions in my case) and save those changes back to Firebase. Can you help?
UPDATE
Based on Frank van Puffelen comments below, I'm adding additional info. Take the following transactions as an example. I pull the following transactions from Firebase and I order them by "customIndex". So if I "move" customindex: "5" (Starbucks transaction) between customindex: "1" (McDonalds) and customindex: "2" (Walmart)
{
"accounts": {"Checking":
{payee: "McDonalds", amount: "2.35", customindex: "1"}
{payee: "Walmart", amount: "78.12", customindex: "2"}
{payee: "CapitalOne", amount: "150.00", customindex: "3"}
{payee: "FootLocker", amount: "107.54", customindex: "4"}
{payee: "Starbucks", amount: "2.88", customindex: "5"}
}}
I should end up with the following data in Firebase:
{
"accounts": {"Checking":
{payee: "McDonalds", amount: "2.35", customindex: "1"}
{payee: "Starbucks", amount: "2.88", customindex: "2"}
{payee: "Walmart", amount: "78.12", customindex: "3"}
{payee: "CapitalOne", amount: "150.00", customindex: "4"}
{payee: "FootLocker", amount: "107.54", customindex: "5"}
}}
I hope this helps making it more clear and thank you in advanced for your help!
To order your items, leave it to Firebase. For example say that you want the transactions to be ordered on creation date, you could:
var ref = fb.child("members")
.child(fbAuth.uid)
.child("accounts")
.child($scope.AccountId)
.child("transactions")
.orderByChild("creationDate");
$scope.transactions = $firebaseArray(ref);
If that does not cover what you want, please update your question to be clearer on what you're trying to sort on. Right now, I have no clue what you're trying to sort on.
Update
I just noticed your update and that indeed clarifies what you're trying to accomplish.
In your first data snippet, the data is ordered by customindex. So you can retrieve them in that order by:
var ref = fb.child("members")
.child(fbAuth.uid)
.child("accounts")
.child($scope.AccountId)
.child("transactions")
.orderByChild("customindex");
$scope.transactions = $firebaseArray(ref);
In your last data snippet, the transactions are no longer ordered by any property. So when the user drags the Starbucks transaction from its last place and drops it in second place, you'll need to update the customindex property of all transactions after it. If you update those values, AngularFire will automatically ensure that the items are in the correct order in the $firebaseArray again.
Note that this requires updating 4 transactions, which may not be very efficient. Alternatively you can:
keep the transaction details (what you initially had) and the transaction order in separate nodes. That way you'll only have to update the transaction_order node.
keep some space between your initial indexes. So instead of [1,2,3,4,5], start with [10,20,30,40,50]. Then when the user moves Starbucks up between 20 and 30, you can simply update the Starbucks transaction's customindex to 25: [10,20,25,30,40,50]. This approach is a bit hacky, but is simpler to implement and will normally work pretty well.

Unable to read AT Command Response

I test some basic AT Command in Hyperterminal. The GSM modem response as per my command too. But problem is that it shows me the unreadable text. I use the following code :
AT
OK
AT+CUSD=1,"*247#",15
OK
+CUSD: 1,"0062004B006100730068000A00310020004D0032004D0020005400720061006E007300
6600650072000A0032002000440069007300620075007200730065000A00330020004D0079002000
62004B006100730068000A0034002000480065006C0070006C0069006E0065000A",72
AT+CUSD=1,"1",15
OK
AT+CUSD=1,"*247#",15 command should display
Menu 1
Menu 2
Menu 3
Something like that. But it displayed the hexadecimal code which it unreadable. How can I get plain text ? Can anyone help Me ?
Judging by information provided. Where when you send the +CUSD request with DCS (Data Coding Scheme) of 15. And the response from the Bkash service with DCS of 72. It looks like your modem does not support the encoding specified in the DCS from Bkash.
I found is fairly similar question and solution to this question. Try and ensure that +CSCS is set to something like IRA or GSM and see what happens then with your +CUSD responses.
Use the following functions to decode "UCS2" response data:
public static String HexStr2UnicodeStr(String strHex)
{
byte[] ba = Hex2ByteArray(strHex);
return HexBytes2UnicodeStr(ba);
}
public static String HexBytes2UnicodeStr(byte[] ba)
{
var strMessage = Encoding.BigEndianUnicode.GetString(ba, 0, ba.Length);
return strMessage;
}
for example:
String str2 = SmsEngine.HexStr2UnicodeStr("0062004B006100730068000A00310020004D0032004D0020005400720061006E0073006600650072000A0032002000440069007300620075007200730065000A00330020004D007900200062004B006100730068000A0034002000480065006C0070006C0069006E0065000A");
// str2 = "bKash\n1 M2M Transfer\n2 Disburse\n3 My bKash\n4 Helpline\n"
Please also check UnicodeStr2HexStr()
Hi this code is something called PDU (Protocol Data Unit). To decode it is not straight forward. you need to understand the structure first.

Resources