5

How to create and use C ++ objects in QML Javascript

 3 years ago
source link: https://www.codesd.com/item/how-to-create-and-use-c-objects-in-qml-javascript.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to create and use C ++ objects in QML Javascript

advertisements

My app uses both c++ and QML.

I've defined several objects in C++ part to access SQL etc.

It looks like:

class MyObject : public QObject
{
    Q_OBJECT
public:
    MyObject(QObject *parent = 0);
    Q_INVOKABLE void someFunction(const QString &query);
};

qmlRegisterType<MyObject>("xxx.xxx", 1, 0, "MyObject");

Ideally, I need to use these objects only in Javascript not in QML.

I tried a lot of examples and read all the documentation but still can't solve my problem.

So my questions:

  • How can I instance in Javascript an object defined in C++? I tried var obj = Qt.createComponent("MyObject"); but it seems not works. Is it possible to define new object in normal JS style - var obj = new MyObject;?
  • How can I access this created object in javascript? I tried obj.someFunction("xxx") but got some error - TypeError: Property 'someFunction' of object QQmlComponent(0x3605f5c0) is not a function. What I do wrong here? My object derived from QObject, not from QQmlComponent.

Your object isn't a Component, but you can use Qt.createQmlObject instead.

Related Articles

How to create and use an object of another class in Java

This question already has an answer here: Accessing objects of other classes 3 answers I dont know how to create and use an object from an other class in an other class. for example, i want the Publisher to be created from another class (Item) public

How to create and use an object with Objective-C?

Im programming with objective c for ios. I have a problem...i create a class object this is the Item.h @interface Item : NSObject { NSString *date; NSMutableArray *a; NSMutableArray *b; NSMutableArray *c; NSMutableArray *d; NSMutableArray *e; NSMutab

How to create and use a C ++ static library for the ios application

I know how to build a object C static library using iOS->Framework&Library->Cocoa Touch Static Library in xcode 4.6, and it is straightforward with the help of this tutorial Creating a Static Library in iOS Tutorial. One thing I am not sure, how

How to create and use C # dll files

I am currently trying to learn how to write and use .dll files for Windows in C# and C++. I think once I understand one of those langueages I will be able to figure out the other one quite easily. I have searched for over 5 hours today but have had n

How to create and use LESS models?

I want to get a general idea of how to make and use LESS templates. I'm guessing a template should consist of css rules which makes use of less @variables, and when you simply @import that template into another .less file that contains defined variab

Delphi: How to create and use Thread locally?

My database is in a VPS and I should get some query from my tables Because of getting query from server taking long time ( depending on Internet speed ! ) , I want to use threads to get queries Now I create a thread and get query and then send result

How to sum values ​​using an object? In JavaScript

I have created a function to sum the values but It does not get the result expected, return 0 function ints(t) { this.t=t; } ints.prototype.sum = function() { var sum = 0; var value; for (var _ in this.t) { value = _; sum += value; } return sum; } va

How to create and use self-hosted objects to share custom stories on Android?

I am developing a game app. And I am sharing facebook custom stories in my app.I have created a self hosted object(html page). I want to use that same self hosted object in android,ios and Facebook canvas app. I have already done custom story sharing

Is the bad / inefficient way to create and use PDO objects in php?

I'm messing around with an example site from teamtreehouse's PHP/MySQL project... In their 'model' code, they have all DB calls inside functions inside a file called products.php.. each of these functions will create a new PDO object by importing an

How to create and use ffmpeg in Android

I am prototyping a fairly simple camera app to test out using MediaRecorder to create a custom camera activity with one snag, I want to set the aspect ratio of recorded videos to a 1x1. Through much research I have found that this is only possible by

How to create and use UDF on cloud datalab?

I created a udf called "passthrough" using the command, %%bigquery udf -m passthrough function passthrough(row, emit) { emit({outputA: row.inputA, outputB: row.inputB}); } bigquery.defineFunction( 'passthrough', ['inputA', 'inputB'], [{'name': '

How to create and use a 1D layered texture in CUDA

I am new to CUDA. I have figured out how to do 1D and 2D textures in CUDA. However, I am struggling with how to use a 1D layered texture. The output of my kernel which uses the texture is all zeros, which is definitely incorrect. However, I am not su

how to create and use a self-defined shared library with gcc?

I'm trying to write a simple example shared library makefile, but I met some bugs and cannot handle it, please help me, thanks. This is my makefile: exampleMain.o: exampleMain.cpp g++ -std=c++11 -I./ -Wall -g -c exampleMain.cpp # (1) Basic example.o:

How to declare and use the object in this build.sbt?

I am trying to understand how to write a well-written build.sbt file, and followed a tutorial on youtube. In that tutorial an object is created similar as below, but what I have written gives the shown error. What am I doing wrong? I have tried to re

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK