Perl Qt 3.1和线程

时间:2011-11-09 03:21:14

标签: multithreading perl qt slots qt-signals

我有一个类是Qt :: Object,并且有一个创建线程的方法。

每当我尝试分离或加入线程时,它就会出错。

发射信号也不起作用。

示例代码为:

package MyThread;

use threads;

use Qt;
use Qt::isa qw(Qt::Object);
use Qt::signals
 imageResRecieved   => ['int', 'int'];

sub NEW
{
    shift->SUPER::NEW(@_[0..2]);
    if ( name() eq "unnamed" ) {
        setName("MyThread" );
    }
}

sub getWidthHeight{
   my ($seq, $frameNum) = @_;  
   my ($width, $height) = (1920, 1080);
   sleep(2);
   print "Emitting\n";
   emit imageResRecieved($width, $height);
   print "AFTER Emit\n";
}


sub getImageWidthThread{
  my $thr = threads->create('getWidthHeight', @_);

  $thr->detach(); # This causes seg faults 
}

use MyThread;
use Qt::slots
    handleImageResSignal    => ['int', 'int'];

    my $mythread = MyThread();
    Qt::Object::connect($irt, SIGNAL "imageResRecieved(int, int)", this, SLOT "handleImageResSignal(int, int)");
    $mythread->getImageWidthThread("$GLOBAL{DIR}/$GLOBAL{PAT}", $seq_start);

    sub handleImageResSignal{
      my ($width, $height) = @_; 
      print "\n Emitted ${width} ${height} \n";
}

我得到的错误就像:

尝试释放不存在的共享字符串'39631808',Perl解释器:0x2879910。

[1]分段错误

1 个答案:

答案 0 :(得分:0)

尝试涉及QThread ...太糟糕了,分发不带示例,你应该请求一个,同时尝试调整http://www.pyside.org/docs/pyside/PySide/QtCore/QThread.html