0

.h

#include <QObject>
#include <QDebug>

class MyClass : public QObject
{
  Q_OBJECT
public:
  Q_INVOKABLE void cppMethod (const QString &msg) 
  {
    qDebug() << "Called the C++ method with" << msg;
  }

public slots:
  void cppSlot (int number) 
  {
    qDebug() << "Called the C++ slot with" << number;
  }
};

.cpp

#include <QtCore/QCoreApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QDeclarativeContext>
#include <QDeclarativeView>
#include <QVariant>
#include <QMetaObject>

#include "cppFromQml.h"

int main (int argc, char *argv[]) 
{
  QCoreApplication a(argc, argv);
  QDeclarativeView view;

  return a.exec();
}

これにより、セグメンテーション違反が発生します。抜け道は?

Qt: 4.8.1

4

1 に答える 1