簡體   English   中英

QT插件,VTK QT小部件,多線程和鏈接問題?

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

大家問候

這將是一個很長的問題,如果不是那么必要,請跳過[背景];)

[背景 ]

我正在開發基於QT的模塊化應用程序,該應用程序可通過基於QT的插件擴展。 如圖所示,主要有3個部分。(紅色數字)

替代文字

1) libAppCore-應用程序的核心,它定義了插件接口,主UIS,交互等

2) App.exe-實現一些內置插件和主應用程序執行的應用程序。

3) 基於Qt的插件 -幾個在libAppCore.dll實現插件接口的libAppCore.dll

以下是每個組件相互鏈接的方式:

  • libAppCore鏈接QT庫。

  • App.exe鏈接libAppCore.DLL和QT庫(App.exe使用其他未在我的libAppCore.DLL中使用的QT類)

  • 插件(libAppQTPluginA.DLL,libAppQTPluginB.DLL)-鏈接libAppCore.DLL和QT庫。 libAppQTPluginA.DLL-鏈接OpenGL libAppQTPluginB.DLL-鏈接VTK庫

[實際問題; ]再次僅在Windows中發生,在Linux中工作正常。

一切都可以正常編譯,而在執行使用VTK庫的PluginB時,我只有一個問題。

在執行PluginB的過程中,它將創建一個QWidget,該QWidget設置為QMainWindow中的中央小部件。(一次可以有多個QMainWindow。)在這個QWidget中,我創建了一個QVTWidget並創建了一個虛擬球體,如下所示:

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

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

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

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

在執行期間,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)

(但是當我注釋掉行vboxLayout-> addWidget(qtWidget)時,它消失了。)

當我對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.)

有小費嗎 ? 為什么它在第一次就多個線程進行比較?

最終,我找到了解決方案。.我已經為Release版本編譯了VTK庫。但是我構建了Debug版本的所有其他組件。 由於鏈接了兩個QT庫(發行版和調試版),因此QT為每個版本創建兩個線程。 最后,我使用Release build選項進行構建,一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM