Results 1 to 7 of 7

Thread: segmentation fault on mouse hover

  1. #1
    Join Date
    Aug 2008
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default segmentation fault on mouse hover

    im gonna explain my structure step by step

    i have a widget including a button and a label
    label has a png as background.
    when i click on button a thread is being created
    that thread draws a line chart on that label

    here is my problem:
    when i move my mouse on the png ,my application exits with segmentation fault


    i read data from an array to draw the chart. i update array in another thread.
    i have 2 mutexes to make my threads work consecutively. "1 update 1 draw" i mean.
    draw function adds lines to my scene/view

    another problem:
    if i dont call msleep(30+) after each loop in each thread my program exits with fault again
    30+ = ms under 30 doesnt work also

    if needed i can post my code.
    i need ur help.

    have a good day every1

    ersin özkan
    turkey

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault on mouse hover

    Worker threads are forbidden from drawing anything on widgets. You have to draw from within the main thread.

  3. #3
    Join Date
    Aug 2008
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on mouse hover

    but main thread doesnt update the scene immediately after my thread finish adding lineitems. so i call update() inside thread and it works. but when i mouse over i get error

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault on mouse hover

    There is no "but". You simply can't draw from within worker threads and that's final or else you'll be getting crashes at random moments and that's exactly what is happening. Use signals and slots or custom events to transfer data across threads.

  5. #5
    Join Date
    Aug 2008
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on mouse hover

    wysota; should i do the "addLine to scene" work in main widget also?

    ty for help
    Last edited by elessaar; 26th August 2008 at 12:47.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: segmentation fault on mouse hover

    I am not sure if this will work -
    Pass a canvas / paint device to the thread, and use it in the paint event of the main widget.
    The thread will draw on the canvas while the canvas is member of main widget, hence it can be accessed from the paint event of main widget.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault on mouse hover

    Quote Originally Posted by elessaar View Post
    wysota; should i do the "addLine to scene" work in main widget also?
    All QWidgets are not thread-safe (nor even reentrant as far as I remember) thus all actions related to widgets have to be done from the main thread unless the docs explicitely state otherwise for a particular operation. QGraphicsScene is not a QWidget but it is tightly related to it, so it might not be safe to interface it directly from an external thread. I really suggest you stick to signals and slots if you need multithreading (if you do).

Similar Threads

  1. Hover on mouse over while dragging
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2010, 11:31
  2. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 17:52
  3. Process aborted. Segmentation fault
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 09:12
  4. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 17:35
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 17:30

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.