Results 1 to 3 of 3

Thread: Fatal Signal on invoke methode

  1. #1
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Fatal Signal on invoke methode

    Hi all,
    I'm running into a strange problem:
    - I have a QObject which holds a list of items
    Qt Code:
    1. class CGrowersList : public QObject
    2. {
    3. Q_OBJECT
    4. ...
    5. QQmlListProperty<CGrower> growers();
    6. Q_INVOKABLE CGrower* byShortName(const QString& shortName) const;
    7. private:
    8. QList<CGrower*> m_growers;
    To copy to clipboard, switch view to plain text mode 

    - The CGrowerList item is published to qml via contextproperty in my main.cpp:
    Qt Code:
    1. CGrowersList growers;
    2. viewer.rootContext()->setContextProperty("growers", &growers);
    To copy to clipboard, switch view to plain text mode 

    - the m_growers are used as a model for list:
    Qt Code:
    1. QQmlListProperty<CGrower> CGrowersList::growers(){
    2. return QQmlListProperty<CGrower>(this, m_growers);
    3. }
    To copy to clipboard, switch view to plain text mode 

    this works so far so good.
    Problem appears when i try to invoke the methode "byShortName" from within the qml-code.
    Qt Code:
    1. CGrower* CGrowersList::byShortName(const QString& shortName) const {
    2. qDebug() << "enter by shortname: " << shortName;
    3. foreach (CGrower* item, m_growers) {
    4. if (item->shortName().compare(shortName) == 0){
    5. qDebug() << "return : " << item->name();
    6. return item;
    7. }
    8. }
    9. qDebug() << "return nullgrower: ";
    10. return m_nullGrower;
    11. }
    To copy to clipboard, switch view to plain text mode 
    It works 2-10 times and suddenly I get a Fatal signal 11 (SIGSEGV). The methode is entered
    correctly but when the methode tries to access its member (m_growers) it crashes.
    I call several methodes on the CGrowersList wrapper, e.g. sort, filter,... Everything works perfectly
    as long as I don't return a object. Same problem appears if I try to use a "at" function.
    Any ideas?

    Thx,
    Patrik

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fatal Signal on invoke methode

    When you return a QObject from a Q_INVOKABLE then the QML engine will assume that it is now the owner of the object and has to delete it.

    In your case you don't want that, you want to keep ownership with the C++ side.

    Qt Code:
    1. QQmlEngine::setObjectOwnership(item, QQmlEngine::CppOwnership);
    2. return item;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Fatal Signal on invoke methode

    Hi Anda,
    you saved my day
    Many thanks,
    Patrik

Similar Threads

  1. How to invoke Mingw Compiler?
    By parulkalra14 in forum Qt Programming
    Replies: 8
    Last Post: 16th January 2014, 08:38
  2. Replies: 3
    Last Post: 29th September 2013, 11:46
  3. Can not invoke contextMenuEvent in QGraphicsView
    By chiaminhsu in forum Qt Programming
    Replies: 3
    Last Post: 29th April 2013, 21:55
  4. Invoke slot from a non-QThread
    By stephelton in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2013, 10:33
  5. When and where to invoke QAbstractItemView::setIndexWidge?
    By mallun.wang in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2009, 09:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.