简体   繁体   English

QT插件,VTK QT小部件,多线程和链接问题?

[英]QT Plugin , VTK QT Widget , Multi-thread and Linking question?

Greetings all, 大家问候

This is going to be a long question,skip the [Background] if its not that neccasary ;) 这将是一个很长的问题,如果不是那么必要,请跳过[背景];)

[Background ] [背景 ]

I am developing a modular QT based application.Application is extentible via QT based plugins. 我正在开发基于QT的模块化应用程序,该应用程序可通过基于QT的插件扩展。 As shown in the figure, there are mainly 3 parts .(numbers in red) 如图所示,主要有3个部分。(红色数字)

替代文字

1) libAppCore - the core of the application,which defines pluginterfaces,main UIS,interations..etc 1) libAppCore-应用程序的核心,它定义了插件接口,主UIS,交互等

2) App.exe - the applicatoin which implement some builtin plugins and main application execution. 2) App.exe-实现一些内置插件和主应用程序执行的应用程序。

3) Qt based plugins - several plugins which implements Plugin interfaces in libAppCore.dll 3) 基于Qt的插件 -几个在libAppCore.dll实现插件接口的libAppCore.dll

Here's how each components links each other: 以下是每个组件相互链接的方式:

  • libAppCore links QT libraries. libAppCore链接QT库。

  • App.exe links libAppCore.DLL and QT libraries (App.exe uses someother QT Classes not being used my libAppCore.DLL) App.exe链接libAppCore.DLL和QT库(App.exe使用其他未在我的libAppCore.DLL中使用的QT类)

  • Plugins (libAppQTPluginA.DLL , libAppQTPluginB.DLL ) - link libAppCore.DLL and QT libs. 插件(libAppQTPluginA.DLL,libAppQTPluginB.DLL)-链接libAppCore.DLL和QT库。 libAppQTPluginA.DLL - links OpenGL libAppQTPluginB.DLL - links VTK libraries libAppQTPluginA.DLL-链接OpenGL libAppQTPluginB.DLL-链接VTK库

[Actual Problem ; [实际问题; ] Again only occurs in Windows , works fine in Linux. ]再次仅在Windows中发生,在Linux中工作正常。

Everything compiles fine and I have only problem wihen executing the PluginB , which uses VTK libraries. 一切都可以正常编译,而在执行使用VTK库的PluginB时,我只有一个问题。

During executing PluginB , it creates a QWidget which set as central widget in a QMainWindow.(there can be many QMainWindow's at once) Inside this QWidget I create a QVTWidget and create a dummy sphere as follows, 在执行PluginB的过程中,它将创建一个QWidget,该QWidget设置为QMainWindow中的中央小部件。(一次可以有多个QMainWindow。)在这个QWidget中,我创建了一个QVTWidget并创建了一个虚拟球体,如下所示:

QVTKWidget qtWidget = new QVTKWidget(this); QVTKWidget qtWidget =新的QVTKWidget(this); qtWidget->resize(512, 512); qtWidget-> resize(512,512);

vtkSmartPointer sphereSource = vtkSmartPointer::New(); vtkSmartPointer sphereSource = vtkSmartPointer :: New(); sphereSource->Update(); sphereSource-> Update(); vtkSmartPointer sphereMapper = vtkSmartPointer::New(); vtkSmartPointer sphereMapper = vtkSmartPointer :: New(); sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); sphereMapper-> SetInputConnection(sphereSource-> GetOutputPort()); vtkSmartPointer sphereActor = vtkSmartPointer::New(); vtkSmartPointer sphereActor = vtkSmartPointer :: New(); sphereActor->SetMapper(sphereMapper); sphereActor-> SetMapper(sphereMapper);

// VTK Renderer vtkSmartPointer leftRenderer =vtkSmartPointer::New(); // VTK渲染器vtkSmartPointer leftRenderer = vtkSmartPointer :: New(); leftRenderer->AddActor(sphereActor); leftRenderer-> AddActor(sphereActor);

qtWidget->GetRenderWindow()->AddRenderer(leftRenderer); qtWidget-> GetRenderWindow()-> AddRenderer(leftRenderer); QVBoxLayout *vboxLayout = new QVBoxLayout; QVBoxLayout * vboxLayout =新的QVBoxLayout; vboxLayout->addWidget(qtWidget); vboxLayout-> addWidget(qtWidget); setLayout(vboxLayout); setLayout(vboxLayout);

During execution QT warns about multiple threads ,but I never create any new threads nor VTK (AFAIK). 在执行期间,QT警告多个线程,但是我从不创建任何新线程或VTK(AFAIK)。

QObject: Cannot create children for a parent that is in a different thread.(Parent is QObject(0xdbe0d70), parent's thread is QThread(0x3370f8), current thread is QThread(0xdc427f8)

(But when I comment out the line vboxLayout->addWidget(qtWidget); this disappears. ) (但是当我注释掉行vboxLayout-> addWidget(qtWidget)时,它消失了。)

And when I perforce any operation on QVTKWidget ,application crash .Error log is 当我对QVTKWidget执行任何操作时,应用程序崩溃。错误日志为

> Program received signal SIGSEGV,
> Segmentation fault. 0x01024c41 in
> QRegion::isEmpty (this=0x28d480) at
> painting\qregion.cpp:3975 3975   
> painting\qregion.cpp: No such file or
> directory.
>         in painting\qregion.cpp (gdb) back
> #0  0x01024c41 in QRegion::isEmpty (this=0x28d480)
>     at painting\qregion.cpp:3975
> #1  0x00f0f18a in QWidgetPrivate::childAt_helper
> (this=0xf3957a0, p=...,
>     ignoreChildrenInDestructor=false) at kernel\qwidget.cpp:9641
> #2  0x00f0f109 in QWidgetPrivate::childAt_helper
> (this=0xb3c8218, p=...,
>     ignoreChildrenInDestructor=false) at kernel\qwidget.cpp:9636
> #3  0x00f0ef9e in QWidget::childAt (this=0x3be0b0, p=...)
>     at kernel\qwidget.cpp:9600
> #4  0x00f27bb6 in QETWidget::translateMouseEvent
> (this=0xf3701e8, msg=...)
>     at kernel\qapplication_win.cpp:3114
> #5  0x00f234db in QtWndProc@16 (hwnd=0x70af4, message=513, wParam=1,
>     lParam=14090539) at kernel\qapplication_win.cpp:1629
> #6  0x767a6238 in USER32!IsDialogMessageW ()    from
> C:\Windows\syswow64\user32.dll
> #7  0x00070af4 in ?? () warning: (Internal error: pc 0x200 in read in
> psymtab, but not in symtab.)
> 
> warning: (Internal error: pc 0x200 in
> read in psymtab, but not in symtab.)
> 
> #8  0x00000201 in ?? (warning: (Internal error: pc 0x200 in read in
> psymtab, but  not in symtab.)

Any tips ? 有小费吗 ? Why it compains about multiple thread at the first time? 为什么它在第一次就多个线程进行比较?

Finally I found the solution.. I had compiled VTK libraries for Release version.But all other components I build Debug version. 最终,我找到了解决方案。.我已经为Release版本编译了VTK库。但是我构建了Debug版本的所有其他组件。 Since there are two QT libraries are linked(Release and Debug version), QT create two threads for each version. 由于链接了两个QT库(发行版和调试版),因此QT为每个版本创建两个线程。 Finally I build all with Release build option and everything works fine. 最后,我使用Release build选项进行构建,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM