How to call a non-parameterised QML function from C++ - javascript

I am trying to call a function in my QML:
function resetSomething() {
tempVar= undefined
}
I am not sure how to write the invokeMethod for this function.
I tried using something like that:
QQuickItem* qObj= findChild<QQuickItem>("temp");
if (qObj)
{
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething",Q_RETURN_ARG,QVariant,returnArg));
}
But it gives the error
no matching function resetSomething(QVariant) found.

As you can see in your error message Qt's Meta Object System is trying to find method resetSomething(QVariant), but your method doesn't have any parameters. I guess it's because of wrong Q_RETURN_ARG macro usage.
Seems that you can simply fix it like this:
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnArg));
Also I suggest you to read official Qt documentation, it is brilliant.
BTW: Nice repo from Google with a lot of C++/JavaScript intercommunication. You can find a lot of useful patterns there.

Related

Why Frida (Inject) doesn't hook getPackageInfo and other methods?

I am having problems creating a script in JavaScript for Frida.
I want to hook the getPackageInfo method in order to log when it is called in the console, i have overloaded the old and the new version of it using this code:
jPM = Java.use('android.content.pm.PackageManager');
jPM.getPackageInfo.overload('java.lang.String','int').implementation=(pname,f)=>{
console.warn("Called => getPackageInfo ("+f+")");
return jPM.getPackageInfo.call(this,pname,f);
}
jPM.getPackageInfo.overload('android.content.pm.VersionedPackage','int').implementation=(vp,f)=>{
console.warn("Called => getPackageInfo [API level 33] ("+f+")");
return jPM.getPackageInfo.call(this,vp,f);
}
When i try to run the script I don't get any error, but I don't get any log in the console.
I am sure that the method that is being called is the first, because it's signature is this in smali:
Landroid/content/pm/PackageManager;->getPackageInfo(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
I can't understand what am I doing wrong, if i use the same code to hook other methods it works. Please help me
I have solved this by using android.app.ApplicationPackageManager instead of android.content.pm.PackageManager.
Thanks to #Robert for giving me the link to this example code: https://codeshare.frida.re/#limyout/test/

TypeError: c is not a constructor Exception is thrown during inherit from Rally.example.BareMetalChart and Rally.ui.chart.Chart classes

I'm trying to build Chart using rallydev examples but unfortunately, TypeError: c is not a constructor Exception is thrown:
Error: success callback for Deferred transformed result of Deferred transformed result of Deferred threw: TypeError: c is not a constructor
at eval (eval at getInstantiator (sdk-debug.js:5720), <anonymous>:3:8)
at Object.instantiate (sdk-debug.js:5692)
at Object.create (sdk-debug.js:2303)
at constructor._createApp (sdk-debug.js:225510)
at constructor._launchAppInViewport (sdk-debug.js:225417)
at sdk-debug.js:225374
at constructor._loadTimeboxScope (sdk-debug.js:225505)
at sdk-debug.js:225373
at constructor.<anonymous> (sdk-debug.js:225280)
at constructor.<anonymous> (sdk-debug.js:10091)
However, it happens during inherit from Rally.example.BareMetalChart and Rally.ui.chart.Chart classes only.
Everything works as expected if i do inheritance from Rally.example.StandardReport class.
If anyone faced this the same issue and solved it, i would appreciate any help.
Thank you in advance!
Hmm, I just tested it and it worked for me... Are you using the 2.1 example here? https://help.rallydev.com/apps/2.1/doc/#!/example/bare-metal-chart
That error sounds like it can't find your app class. This is usually caused by a mismatch between your js files and your config.json file. Are you using rally app builder? Usually all that is required is to make sure the class defined in your App.js matches the className specified in the config.json file and making sure App.js is included in the javascripts section. Then just rebuild and you should be good to go.
Or, if you're just directly working on that html file from the example, did you do something to change the class name there? Just make sure that the class created with Ext.define is then referenced by the call to Rally.launchApp down at the bottom and you should be good to go.

Javascript variable function method call

I apologise if this has been asked elsewhere, I looked but without knowing the name for what I am doing is, I couldn't find anything.
Anyways, the code is as follows:
function alertTypeOptions(AlertType, AlertOptions) {
navigator.notification.AlertType(AlertOptions);
}
This code is for a phonegap / cordova application.
The basic idea is that you pass the function a two variables and these are used to execute the appropriate method. Examples of this could be alertTypeOptions('beep', '3') or alertTypeOptions('vibrate', '2000'). This (should) play the default alert tone 3x or vibrate the phone for 2 seconds.
I am currently getting the following error:
02-21 15:36:07.185: E/Web Console(7206): Uncaught TypeError:
Object #<Object> has no method 'AlertType'
at file:///android_asset/www/res/scripts.js:181
Obviously the function is currently just using the alertType variable as written rather than as a variable.
Is there a way to get this to work elegantly? Currently my only thoughts are to use a switch statement with AlertType as the check.
Jack
It looks like you want to access your function using the bracket notation :
navigator.notification[AlertType](AlertOptions);
or rather, if I trust this documentation and if AlertOptions is an array :
navigator.notification[AlertType].apply(navigator, AlertOptions);

monitoring js errors

I am interested in monitoring javascript errors and logging the errors with the callstack.
I am not interested to wrap everything in try-catch blocks.
According to this article http://blog.errorception.com/2011/12/call-stacks-in-ie.html
it's possible inside window.onerror "recursively call .caller for each function in the stack to know the previous function in the stack"
I tried to get the callstack:
window.onerror = function(errorMsg, url, lineNumber)
{
var stk = [], clr = arguments.callee.caller;
while(clr)
{
stk.push("" + clr);
clr = clr.caller;
}
// Logging stk
send_callstack_to_log(stk);
}
but only one step is possible even if the callstack was much longer:
(function()
{
function inside() {it.will.be.exception;};
function middle() {inside()};
function outside() {middle()}
outside();
})();
One step isn't interesting because onerror arguments give me even more information about it.
Yes, I tried it with IE according the article I mentioned above.
Remark: I also tried to open an account on "ERRORCAEPTION" to gather error log. I tested it with IE and "ERRORCAEPTION" recognize that the errors are coming from IE, but I can't find any callstack information in the log I've got there.
Unfortunately this log will not always be available, it lacks line numbers, you can not really rely on it.
Try https://qbaka.com
Qbaka automatically overload bunch of JavaScript functions like addEventListener, setTimeout, XMLHtppRequest, etc so that errors happening in callbacks are automatically wrapped with try-catch and you will get stacktraces without any code modification.
You can try atatus which provides javascript contextual error tracking: https://www.atatus.com/
Take a look here:
https://github.com/eriwen/javascript-stacktrace
That's the one I use on Muscula, a service like trackjs.
I have wrote a program to monitor js error. maybe it will help.
I used three kind of methods to catch exceptions, such as window.onerror, rewrite console.error and window.onunhandledrejection. So I can get Uncaught error, unhandled promise rejection and Custom error
Take a look here: https://github.com/a597873885/webfunny_monitor
or here: https:www.webfunny.cn
It will be help

What triggers "Object cannot be created in this context, Code: 9" in Firefox?

We see this occasionally in web apps on Firefox. What triggers it, and how do we prevent it? It seems to happen sporadically and the error message yields no useful information about line locations.
A quick google search yielded this:
http://blowery.org/2008/02/28/object-cannot-be-created-in-this-context-code-9/
...check your code to see if you’re
trying to grab a reference to the
computed style on a null reference.
It appears to be connected with the Dojo framework.
Edit: Ha. Sorry I gave you your own blog as an answer. I guess I don't completely understand what you're asking for. If you want to avoid the error, you could use object checking before running the applicable code.
function isValidObject(someObject)
{
return typeof someObject != null;
}
var obj1 = "Hello World";
if(isValidObject(obj1))
{
//This code will run
}
if(isValidObject(ob2))
{
//This code will not run
}
Hope that's helpful.

Categories

Resources