svalaskevicius/qtjs-generator

why the v8_isolate always is NULL

ericmayc opened this issue · 28 comments

hi @svalaskevicius ,
in main.cpp of runner module,

in main function, I print v8_isolate, the value always is NULL, I inspect node::Init, never invoke v8::Isolate::New(), is it an error?

node::Init(&argc, const_cast<const char**>(argv), &exec_argc, &exec_argv);
v8_isolate = v8::Isolate::GetCurrent();

Hi!

The v8 isolate should be constructed by node during the init.. Although its not strictly required iirc as the isolates are used to separate the v8 engines in eg different threads, but qtjs, as node is currently single threaded.

Is it causing any problems for you?

Regards

note: what I talk about now always is on android. It is all OK with linux.

Yes, after node::Init, I can not get isolate by calling v8::Isolate::GetCurrent().
I have to modify node::Init,
replace
node_isolate = Isolate::GetCurrent();
by
node_isolate = Isolate::New();
node_isolate->Enter();

There is another question in node::Load(env) which caused signal 11 segmentation fault, I am investigating it now.

Hi @ericmayc, just wanted to check how is it going with the android version - is there anything I could help with?

It worked yesterday night!
I have a question. Why you compile node and runner as a whole? why not separate node from runner as a independent lib?

Nice!

The only reason to compile node and runner as a whole is that I've started
from the combined main function and it was easier at the time..
Do you thing it's worth to split them? I think we'd still need to have the
custom make rule for node to exclude it's main.

Is there a chance you could create a pull request with the changes for
Android? I'm keen to try it :)

In fact, there nearly is nothing to be changed. I changed the code in function processEvents except all problems I have referred to. I removed "qApp->exit(0);".
Can you give me more time to create PR? My work is very busy now.

I hope you split node from runner, I think it is easier for user.

Re PR - cool there is no rush :)

As for splitting nodejs - that makes sense - will see to it when I have a
free moment :)

The binary size - yeah I think that's currently the largest issue left to
solve. A simple solution is to reduce the number of bound classes, but it
also reduces the usability.. Another would be to improve this in cpgf. I
saw @wqking was looking at this a while ago and found that its due to the
variant templates used to pass the values internally. I looked there too
but couldn't find a feasible way to rework them, will return to that though
if it works well on android as it's a lot larger issue for mobile phones
than pc..

Yeah currently the only simple way to reduce the binary size is to only register the classes you need, rather than all classes. By default the code generated by metagen will register all classes.
Reducing binary size is the most difficult work in cpgf, and also in any heavy template based libraries, since template instantiations will generate a lot of type information.

hi @svalaskevicius ,
Can qtjs support handling qml objects in JS? For example, when qml object property is changed and emit a signal, can we listen this signal in JS and do something?

Hi! Yes, signals and slots is the main way to communicate between the two
engines.
See eg IntIncrementer in the qml example.

But if I don't create new QmlComponent, how can I do it?

You could also set an object to qml's context and use it as your api. The
difference being that you'd have only one instance in qml.

The whole integration is very similar to that of cpp-qml, just that the cpp
part is replaced by js :)

Do you have a specific example I could check?

For example, there is an IntIncrementer instance whose id is incrementer in qml, how can I get this object in Js?

IntIncrementer {
id: incrementer
value: 9
onValueChanged: {
status.text += "value changed to " + incrementer.value
}
onIncremented: {
status.text += "value changed to " + newValue
}
}

I want to implement "QObject rect = object->findChild<QObject>("rect");" in JS. I find it has binding QObject to js, which has a template function "qt_qFindChild_helper" , but I don't know how to use it in js.
If it can be used in js. Does it mean we can access object in qml from js?

I cannot find an example now but..

Essentially qtjs doesn't bind the templates as we don't know which
instances will be used (you can check the metagen configs to see which
template instances are available in js and what are their names there) .

There are two ways to do this: either bind the specific template instance
and recompile, or implement this purely in js using a recursive function
that uses qobject children() and name().

If you expect a specific c++ class instance to be returned you'd also need
to cast the result to that class using cpgf's cast function.

I hope this helps :)

For template function such as findChild, I think the better way is to implement it in JS, rather than making metagen to generate template instantiations for it.Each template instantiation will increase the compiling time and binary size.

Hi @svalaskevicius and @wqking , I come again:)
I have another question, I have c++ function whose return type is enum, how should I do with it in cpgf?

Hi Eric,

There is test_reflection_enum.cpp under test/reflection that demonstrates how to use enumerator in cpgf.
Also there are some documentations,
http://www.cpgf.org/document/reflection-build-meta-data.html#reflect-enumerators
http://www.cpgf.org/document/reflection-using-meta-data-lib.html#using-meta-enumerators

Enum class in C++11 is not supported, because it can't be converted to int implicitly.

@svalaskevicius , your last answer
here are two ways to do this: either bind the specific template instance
and recompile, or implement this purely in js using a recursive function
that uses qobject children() and name().


specific template instance is like this?
predefinedTemplateInstances: [
'QList', '',
'QListQTextLayout::FormatRange', 'QList_QTextLayout_FormatRange',
]

How to implement it in js? Can you give a example?

Hey! how is it going?

Found the example I mentioned before - https://github.com/svalaskevicius/qtjs-generator/blob/master/examples/qml.js#L158

The vector api doesn't look nice - might need to create client side shim in js to make it nicer to use

hi @svalaskevicius, I have a question about using QList in Javascript.
I was intending to use QList<QQuickGradientStop*> in Js, and i added following code segment in qtjs-generator/metagen/qtQml_cfg.js as following:
predefinedTemplateInstances: [
'QList < QQuickGradientStop* > ', 'QList_QQuickGradientStop_Ptr',
]

And i used QList_QQuickGradientStop_Ptr in my test.js as following:
/***********************************************************************************/
var list = new qt.QList_QQuickGradientStop_Ptr();

var stop1 = new qt.QQuickGradientStop();
var color1 = new qt.QColor("red");
stop1.setColor(color1);
console.log("in stop1:", stop1.color().value());
stop1.setPosition(0.33);
console.log("in stop1:", stop1.position());

list.append(stop1);

console.log("in list:", list.value(0).color().value());
console.log("in list:", list.value(0).position());
/*********************************************************************************/
It comes up with the result as :
in stop1: 255
in stop1: 0.33
in list: 0
in list: 6.9415221825227e-310

In above code block, after list.append(stop1), it turned out the result the list is not correctly evaluated by stop1.
Would you please help me to find out what the problem is ? Thanks a lot ~

Hi @yinyi26,

I'm not familiar with QtQuick. But, did you bind QQuickGradientStop to script? If so, can you try to use list.at(0) instead of list.value(0) to see if it's correct? at(0) returns a reference while value(0) returns an object.

Thanks @wqking
Yes, i have binded QQuickGradientStop, and i just tried list.at(0) instead of list.value(0), the result is almost the same as before:
in stop1: 255
in stop1: 0.33
in list: 0
in list: 6.90213367143666e-310
It looks like the values in list are random and they are not initialized and evaluated.

I also tried using list.clear() before list.append(), still does not work.

hi @yinyi26 , this indeed looks like a bug.. I've created a separate issue report for it in #23 .

Thanks for letting me know!

Lets continue the discussion in #23 :)

@ericmayc how is it going?

any successes, or problems I could help with?

Also, do you think I can close this ticket?

thanks, it is going well now. I close now.