Results 1 to 3 of 3

Thread: Creating an object of QDeclarativeView results in segmentation fault

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Creating an object of QDeclarativeView results in segmentation fault

    .h

    Qt Code:
    1. #include <QObject>
    2. #include <QDebug>
    3.  
    4. class MyClass : public QObject
    5. {
    6. Q_OBJECT
    7. public:
    8. Q_INVOKABLE void cppMethod (const QString &msg)
    9. {
    10. qDebug() << "Called the C++ method with" << msg;
    11. }
    12.  
    13. public slots:
    14. void cppSlot (int number)
    15. {
    16. qDebug() << "Called the C++ slot with" << number;
    17. }
    18. };
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QDeclarativeEngine>
    3. #include <QDeclarativeComponent>
    4. #include <QDeclarativeContext>
    5. #include <QDeclarativeView>
    6. #include <QVariant>
    7. #include <QMetaObject>
    8.  
    9. #include "cppFromQml.h"
    10.  
    11. int main (int argc, char *argv[])
    12. {
    13. QCoreApplication a(argc, argv);
    14. QDeclarativeView view;
    15.  
    16. return a.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    This results in segmentation fault. What's the way out?

    Qt: 4.8.1

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Creating an object of QDeclarativeView results in segmentation fault

    QDeclarativeView is a widget. Widgets need a QApplication instance. You have a QCoreApplication instance.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    TheIndependentAquarius (8th October 2013)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Creating an object of QDeclarativeView results in segmentation fault

    Thanks for replying.

Similar Threads

  1. How to unload a QDeclarativeView object
    By nestuser in forum Newbie
    Replies: 0
    Last Post: 17th August 2012, 06:45
  2. Replies: 21
    Last Post: 28th September 2010, 10:59
  3. Replies: 15
    Last Post: 26th October 2009, 18:47
  4. Segmentation fault when creating new QString
    By di_zou in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 18:07
  5. QTreeWidget::topLevelItem() results in seg fault.
    By johnny_sparx in forum Qt Programming
    Replies: 11
    Last Post: 24th March 2006, 19:47

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.