Results 1 to 2 of 2

Thread: customwidget and event help

  1. #1
    Join Date
    Jan 2010
    Posts
    39
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default customwidget and event help

    Hi all,

    I need got this problem which I have no idea why it happens and how to remedy it.

    I got a customWidget (groupwidget) with an event button clicked. I pass a QGraphicsScene pointer in the main class (disp) to the customWidget (groupwidget).

    when I add a QGraphicsItem into the QGraphicsScene, I got a seg fault. I am am sure that the inputs to graphicsitem->setRect exists and is correct.

    How to solve this problem?

    groupwidget.h
    Qt Code:
    1. public slots:
    2. void go_clicked();
    3.  
    4. private:
    5. group ingrp;
    6. QGraphicsScene *inscene;
    7. bool *insel;
    8. bool *inblink;
    9.  
    10. QLabel *lbl_grp;
    11. QComboBox *combo_pl;
    12. QPushButton *btn_grp;
    To copy to clipboard, switch view to plain text mode 

    groupwidget.cpp
    Qt Code:
    1. groupWidget::groupWidget(const group &grp, QGraphicsScene *scene, bool *sel, bool *blink)
    2. {
    3. ingrp = grp;
    4. inscene = scene;
    5. insel = sel;
    6. inblink = blink;
    7.  
    8. combo_pl = new QComboBox;
    9.  
    10. combo_pl->addItem("---Select---");
    11.  
    12. foreach (place p, grp.building)
    13. combo_pl->addItem(p.placename);
    14.  
    15. combo_pl->setMinimumWidth(200);
    16.  
    17. btn_go = new QPushButton;
    18. btn_go->setText("Go");
    19. btn_go->setMaximumWidth(50);
    20.  
    21. lbl_grp = new QLabel;
    22. lbl_grp->setText(grp.grpname);
    23.  
    24. QGridLayout *layout = new QGridLayout;
    25. layout->addWidget(lbl_grp, 0, 0);
    26. layout->addWidget(combo_pl, 1, 0);
    27. layout->addWidget(btn_go,1,1);
    28.  
    29. setLayout(layout);
    30. connect(btn_go, SIGNAL(clicked()), this, SLOT(go_clicked()));
    31. }
    32.  
    33. void groupWidget::go_clicked()
    34. {
    35. QPoint pt;
    36. bool stat = false;
    37.  
    38. foreach (place p, ingrp.building)
    39. {
    40. if ((combo_pl->currentText().trimmed().compare(p.placename)) == 0)
    41. {
    42. bool ok;
    43. pt.setX(p.x.toInt(&ok,10));
    44. pt.setY(p.y.toInt(&ok,10));
    45. stat = true;
    46. }
    47.  
    48. if (stat)
    49. break;
    50. }
    51.  
    52. if (!stat) {
    53. *insel = false;
    54. *inblink = false;
    55. return;
    56. }
    57.  
    58. item->setRect(pt.x(), pt.y(), ellsize, ellsize);
    59. item->setBrush(Qt::red);
    60. inscene->addItem(item); //seg fault
    61.  
    62. *insel = true;
    63. *inblink = true;
    64. }
    To copy to clipboard, switch view to plain text mode 

    disp.h
    Qt Code:
    1. private:
    2. void createPlace();
    3. QWidget *createCellWidget(group grp);
    4. ....
    5. bool blink_stat, sel_item;
    6. ....
    To copy to clipboard, switch view to plain text mode 

    disp.cpp
    Qt Code:
    1. disp::disp(mapinfo in_map)
    2. {
    3. ....
    4. scene = new QGraphicsScene;
    5. scene->setSceneRect(0, 0, 600, 600);
    6. ....
    7. }
    8. ....
    9. ....
    10. ....
    11. QWidget *disp::createCellWidget(group grp)
    12. {
    13. groupWidget *pgroupWidget = new groupWidget(grp, scene, &sel_item, &blink_stat);
    14. return pgroupWidget;
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customwidget and event help

    please, for another post, try to get the minimum compiled example. most code are unrelated whit the problem,

    One cause to the seg faul is that the QGraphicsScene is not created. in the constuctor of groupWidget, you pass a QGraphicsScen pointer. PROBABLY when you create a groupWidget dont pass a valid QGraphicsScene.

    you create a QGraphicsScene in disp::disp() but not show when this code are called or how is used...

Similar Threads

  1. Paint event function in key press event
    By soumya in forum Qt Programming
    Replies: 6
    Last Post: 2nd February 2010, 12:40
  2. Replies: 10
    Last Post: 15th January 2010, 14:35
  3. how to combine keypress event and mousebuttonpress event?
    By hildebrand in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2009, 23:08
  4. [Qt4.5] event(QEvent * event) freeze application
    By czlowiekcien in forum Newbie
    Replies: 2
    Last Post: 25th May 2009, 20:25
  5. Replies: 0
    Last Post: 23rd October 2008, 12:43

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.