Results 1 to 5 of 5

Thread: Problem with QVector

  1. #1
    Join Date
    Jul 2015
    Posts
    21
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Problem with QVector

    Hey,
    i got a problem with a QVector. I used a QVector before and didnt have problems like this. I hope someone can explain me what I'm doing wrong.
    Header:
    Qt Code:
    1. #ifndef MYQTABLEWIDGETITEM_H
    2. #define MYQTABLEWIDGETITEM_H
    3. #include <QTableWidgetItem>
    4. #include <QVector>
    5. class MyQTableWidgetItem;
    6.  
    7. struct Connections{
    8. MyQTableWidgetItem *connectedItem;
    9. int connection;
    10. };
    11.  
    12. class MyQTableWidgetItem : public QTableWidgetItem
    13. {
    14. public:
    15. MyQTableWidgetItem();
    16. void setConnection(MyQTableWidgetItem *connectedItem, int connection);
    17. private:
    18. QVector<Connections> ConnectedItems;
    19. bool virgin;
    20.  
    21. signals:
    22.  
    23. public slots:
    24.  
    25. };
    26.  
    27. #endif // MYQTABLEWIDGETITEM_H
    To copy to clipboard, switch view to plain text mode 

    source:
    Qt Code:
    1. #include "myqtablewidgetitem.h"
    2. #include <QDebug>
    3. MyQTableWidgetItem::MyQTableWidgetItem()
    4. {
    5. this->virgin = true;
    6. }
    7.  
    8. void MyQTableWidgetItem::setConnection(MyQTableWidgetItem *connectedItem, int connection)
    9. {
    10.  
    11. this->virgin = false;
    12. Connections newConnection;
    13. newConnection.connectedItem = connectedItem;
    14. newConnection.connection = connection;
    15. this->ConnectedItems.push_back(newConnection);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 
    I call this function:
    Qt Code:
    1. this->m_leftItem->setConnection(this->m_topItem,this->counter);
    To copy to clipboard, switch view to plain text mode 
    I get no errors but the following message:
    Signal name : SIGSEGV
    Signal meaning: Segmentation fault

  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: Problem with QVector

    You'll need to check the backtrace of the crash.
    Maybe "m_leftItem" is not a valid pointer.

    Btw, no need to prefix member access with "this->", that is always implicit in C++

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    21
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with QVector

    Hmmm what do you mean with not valid? If I do something like "this->m_LeftItem.text();" its working and I get the text which was saved there.
    thats what I get from the Debugger.
    0 QVector<Connections>::append qvector.h 598 0x409d29
    1 QVector<Connections>:ush_back qvector.h 224 0x409ead
    2 MyQTableWidgetItem::setConnection myqtablewidgetitem.cpp 36 0x403a74
    3 SymbolButton::setCounterOnClick symbolbutton.cpp 68 0x403510
    4 SymbolButton::changeSymbol symbolbutton.cpp 18 0x402aab
    5 SymbolButton::qt_static_metacall moc_symbolbutton.cpp 92 0x4043e6
    6 QMetaObject::activate C:/Qt/5.4/mingw491_32/bin/Qt5Cored.dll 3717 0x6b95a575
    7 QMetaObject::activate C:/Qt/5.4/mingw491_32/bin/Qt5Cored.dll 3582 0x6b959eba
    8 QAbstractButton::clicked C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 298 0x9f720c3
    9 QAbstractButtonPrivate::emitClicked C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 534 0x9d353a9
    10 QAbstractButtonPrivate::click C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 527 0x9d35344
    11 QAbstractButton::mouseReleaseEvent C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 1132 0x9d36643
    12 QWidget::event C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 8657 0x9c73ecf
    13 QAbstractButton::event C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 1089 0x9d364b8
    14 QPushButton::event C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 673 0x9dc3942
    15 QApplicationPrivate::notify_helper C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 3720 0x9c3f4dd
    16 QApplication::notify C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 3280 0x9c3d61c
    17 QCoreApplication::notifyInternal C:/Qt/5.4/mingw491_32/bin/Qt5Cored.dll 935 0x6b92f330
    18 QCoreApplication::sendSpontaneousEvent C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 231 0x9f9ee85
    19 QApplicationPrivate::sendMouseEvent C:/Qt/5.4/mingw491_32/bin/Qt5Widgetsd.dll 2751 0x9c3c1a1
    ... <Mehr>
    Always if I want to put my struct in the QVector my program crash.

  4. #4
    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: Problem with QVector

    When something like that crashes it usually means that "this" is not a valid instance.
    For example an uninitialized pointer or an already deleted object.

    In your SymbolButton::setCounterOnClick(), how do you get access to the item on which you then call setConnection?

    Cheers,
    _

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

    ReasyEasyPeasy (19th October 2015)

  6. #5
    Join Date
    Jul 2015
    Posts
    21
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with QVector

    I got it thanks!

Similar Threads

  1. Replies: 5
    Last Post: 3rd September 2011, 00:11
  2. QVector.push_back problem...
    By luche in forum Newbie
    Replies: 2
    Last Post: 11th January 2009, 03:22
  3. Problem regarding QVector
    By sudheer168 in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2008, 12:56
  4. Problem with qvector
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2008, 02:02
  5. QVector problem
    By kingslee in forum Qt Programming
    Replies: 5
    Last Post: 19th October 2006, 11:42

Tags for this Thread

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.