Hi!

I'm meaning to grab some data from a network connection, wrap the data into a QFrame and add those QFrames to my gui. The data comes slow, so it has to be a seperate process that doesn't block the gui. Also the user needs to have the possibility to stop the process in the middle. So what I did is this:

Qt Code:
  1. class FrameGrabber : QThread;
  2.  
  3. void GUI::on_startGrabButton_clicked()
  4. {
  5. // Start the grabber thread.
  6. frameGrabber.start();
  7. }
To copy to clipboard, switch view to plain text mode 

And inside the frameGrabber thread:

Qt Code:
  1. class MyFrame : QFrame;
  2.  
  3. void FrameGrabber::run()
  4. {
  5. int framesToGrab =1000;
  6.  
  7. while(framesToGrab >= 0)
  8. {
  9. MyFrame* f = NetworkConnection::grabFrame();
  10. GUI->addFrame(f);
  11. framesToGrab--;
  12. msleep(10);
  13. }
  14.  
  15. GUI->grabbingProcessFinished();
  16. }
To copy to clipboard, switch view to plain text mode 

The NetworkConnection class will instantiate a MyFrame, which is derived from QFrame. However, since the NetworkConnection doesn't know anything about the GUI, it cannot pass QWidget* parent as an argument to the constructor, so it can't instantiate a full blown QFrame yet. Only when MyFrame is added to the GUI with GUI->addFrame(), I try to set the parent with the setParent() method:

Qt Code:
  1. void GUI::addFrame(MyFrame* f)
  2. {
  3. f->setParent(ui.GrabbedFrameBufferArea);
  4. }
To copy to clipboard, switch view to plain text mode 

This was the plan anyhow, but it doesn't work. I get a lot of this:

QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::setParent: Cannot set parent, new parent is in a different thread
I don't quite get why it complains about a different thread adding Widgets to the gui. But in any case, what would be the right solution?

Thanks
Cruz