How about using Qt.createQmlObject()
? The problem is you need to supply a parent item when creating an object. The other being unable to call non-default constructor.
// C++ class (from http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html)
class Message : public QObject
{
Q_OBJECT
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
Q_PROPERTY(QDateTime creationDate READ creationDate WRITE setCreationDate NOTIFY creationDateChanged)
public:
// ...
};
// Register the C++ class to be used by QML
qmlRegisterType<Message>("com.mycompany.messaging", 1, 0, "Message");
// Create C++ object from QML JavaScript
var msg = Qt.createQmlObject('import com.mycompany.messaging 1.0; Message {}', parentItem);
msg.author = "Kate";