Results 1 to 5 of 5

Thread: QSlider Update Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    68
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default Re: QSlider Update Problem

    Well, even if I push the fader up real slow.. say 6 seconds from bottom to top, the same problem occurs.

    That would mean around 16 messages per second.The code in the MIDI thread is actually still a bit of a mystery to me.. as its taken from some other o/s projects

    Qt Code:
    1. void midiThread::run()
    2. {
    3. snd_seq_t *seq_handle;
    4. int npfd;
    5. struct pollfd *pfd;
    6.  
    7. seq_handle = open_seq();
    8. npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
    9. pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
    10. snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
    11. while (1) {
    12. if (poll(pfd, npfd, 100000) > 0) {
    13. midi_action(seq_handle);
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    This is the run part of the QThread. The other relevant bit is:

    Qt Code:
    1. void midiThread::midi_action(snd_seq_t *seq_handle) {
    2.  
    3. snd_seq_event_t *ev;
    4. MyDataEvent dataEvent(0,0);
    5.  
    6. do {
    7. snd_seq_event_input(seq_handle, &ev);
    8. switch (ev->type) {
    9. case SND_SEQ_EVENT_CONTROLLER:
    10. dataEvent.setParam(ev->data.control.param);
    11. dataEvent.setValue(ev->data.control.value);
    12. QApplication::sendEvent( parent, &dataEvent );
    13. break;
    14. }
    15.  
    16. snd_seq_free_event(ev);
    17. } while (snd_seq_event_input_pending(seq_handle, 0) > 0);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    If this is a horrible way to do things.. I would much appreciate any ideas on how to handle MIDI better.

    On windows I used Borland C++ Builder.. and found a great component that pretty much did it all for me, passing the messages to my callback function. I guess I have to learn more C++ to program on Linux ;-)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSlider Update Problem

    Quote Originally Posted by December
    That would mean around 16 messages per second.
    Then it shouldn't be a problem, unless you do a busy-wait somewhere. You check with top if your program doesn't eat whole CPU power.

    poll() is a good way to go, but in midi_action() you have a problem --- you use sendEvent(), but only postEvent() is thread-safe.

    Try:
    Qt Code:
    1. void midiThread::midi_action(snd_seq_t *seq_handle) {
    2. ...
    3. do {
    4. snd_seq_event_input(seq_handle, &ev);
    5. switch (ev->type) {
    6. case SND_SEQ_EVENT_CONTROLLER:
    7. MyDataEvent *dataEvent = new MyDataEvent(0,0);
    8. dataEvent.setParam(ev->data.control.param);
    9. dataEvent.setValue(ev->data.control.value);
    10. QApplication::postEvent( parent, dataEvent ); // QApplication takes ownership of the event
    11. break;
    12. }
    13. ...
    To copy to clipboard, switch view to plain text mode 

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

    December (10th September 2006)

  4. #3
    Join Date
    Sep 2006
    Posts
    68
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default Re: QSlider Update Problem

    Wow, that was the problem.

    Changing from using sendEvent to postEvent solved it. I feel stupid now, I even remember reading that sendEvent is not thread safe a while back

    Thanks for the help.. I think QT is going to be a lot of fun with such knowledgeable people around

Similar Threads

  1. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13
  2. Replies: 16
    Last Post: 7th March 2006, 15:57
  3. hide/show screen update problem
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2006, 17:49
  4. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 18:24
  5. Record update windowd entered data saving
    By MarkoSan in forum Qt Programming
    Replies: 56
    Last Post: 18th January 2006, 18:50

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
  •  
Qt is a trademark of The Qt Company.