Hi everyone,

i've been reading the forums for some time but now i need some help

I tried to boil it down to the most simples case to show it here:

I have a qml file simply taken from one of the official tutorials.
It's a simple button. lets call it button2.

I have a cpp code, that generates a window and a button, button1.
Once the button1 is pressed, QDeclarativeView is used to view the qml file and a window pops up showing button1.

Pressing button2 (the qml button) should connect to a cpp slot that will show a message on terminal.

Everything works fine, but when i click on button2 i get a segfault.

Here is the code.
I was not sure if i'm supposed to post the entire code (with all the indcludes and stuff).
I hope its ok to post the code in such a way.


Qt Code:
  1. //Button.qml
  2. import QtQuick 1.0
  3.  
  4. Rectangle
  5. {
  6. id: button
  7. width: 75; height: 50
  8.  
  9. Text
  10. {
  11. id: buttonLabel
  12. anchors.centerIn: parent
  13. text: "click here"
  14. }
  15.  
  16. MouseArea
  17. {
  18. id: buttonMouseArea
  19. anchors.fill: parent
  20. onClicked: buttonClick()
  21. }
  22.  
  23. signal buttonClick()
  24. onButtonClick:
  25. {
  26. qmlSlot.cppMethod("Hello from QML") //this is the cpp slot i whant to call
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //myqml.h
  2.  
  3. class MyClass : public QWidget
  4. {
  5. Q_OBJECT
  6.  
  7. public:
  8. MyClass(QWidget *parent = 0);
  9.  
  10. private slots:
  11. void showQmlSlot(); //this is the slot to view the qml file
  12. Q_INVOKABLE void cppMethod(const QString &msg) {
  13. qDebug() << "Called the C++ method with" << msg;
  14. }//this is the cpp slot to be called within the qml file
  15.  
  16. private:
  17. QPushButton *click;
  18. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //myqml.cpp
  2.  
  3. MyClass::MyClass(QWidget *parent)
  4. : QWidget(parent)
  5. {
  6. click = new QPushButton("Click me", this);
  7. click->setGeometry(50, 40, 75, 30);
  8.  
  9. connect(click, SIGNAL(clicked()),
  10. this, SLOT(showQmlSlot()));
  11. }
  12.  
  13.  
  14. void MyClass::showQmlSlot()
  15. {
  16. MyClass myClass;
  17.  
  18. QDeclarativeView *view = new QDeclarativeView();
  19.  
  20. view->setSource(QUrl::fromLocalFile("Button.qml"));
  21. view->rootContext()->setContextProperty("qmlSlot", &myClass);
  22.  
  23. view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
  24. view->show();
  25. }
To copy to clipboard, switch view to plain text mode 


I just dont get where the error comes from.
Funny enought, if i use the QDeclarativeView within the main.cpp,
like shown for instance here
http://www.developer.nokia.com/Commu...ation_from_QML
it works fine...

Thanks for helping me