[Insight-users] [vtkusers] QWidget:Must construct a QApplication before a QPaintDevice
Dženan Zukić
dzenanz at gmail.com
Mon Aug 15 04:35:37 EDT 2011
Since I use VTK 5.6.1, and not the current development version I do
not have QVTKApplication.h. The following code works (screenshot
attached) on my computer:
#include "qmainwindow.h"
#include "qapplication.h"
#include <QVTKWidget.h>
//#include <QVTKApplication.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkTextSource.h>
#include <vtkVectorText.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
int main( int argc, char **argv )
{
QApplication app(argc,argv);
QMainWindow *mainWindow = new QMainWindow;
mainWindow->setFixedSize(640,360);
QVTKWidget *widget = new QVTKWidget;
mainWindow->setCentralWidget(widget);
vtkTextSource *text = vtkTextSource::New();
text->SetText("Hello World!");
text->BackingOff();
vtkVectorText *vectorText = vtkVectorText::New();
vectorText->SetText("QVTKWidget");
vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New();
textMapper->SetInput(text->GetOutput());
vtkPolyDataMapper *vectorTextMapper = vtkPolyDataMapper::New();
vectorTextMapper->SetInput(vectorText->GetOutput());
vtkActor *textActor = vtkActor::New();
textActor->SetMapper(textMapper);
vtkActor *vectorTextActor = vtkActor::New();
vectorTextActor->SetMapper(vectorTextMapper);
vtkRenderer *renderer = vtkRenderer::New();
renderer->SetBackground(0.4,0.6,0.8);
renderer->AddActor(textActor);
renderer->AddActor(vectorTextActor);
vtkRenderWindow *renderWindow = vtkRenderWindow::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetStereoTypeToDresden();
widget->SetRenderWindow(renderWindow);
mainWindow->show();
app.aboutQt();
return app.exec();
}
2011/8/15 Leonid Dulman <leonid_dulman at yahoo.co.uk>
>
> I changed release VTK building to Debug (VC 2010), but in Windows 7 SP1 have got message
> "QWidget:Must construct a QApplication before a QPaintDevice"
> Thank you Leonid
>
>
> --- On Mon, 15/8/11, Dženan Zukić <dzenanz at gmail.com> wrote:
>
> From: Dženan Zukić <dzenanz at gmail.com>
> Subject: Re: [vtkusers] QWidget:Must construct a QApplication before a QPaintDevice
> To: "Leonid Dulman" <leonid_dulman at yahoo.co.uk>
> Cc: vtkusers at vtk.org
> Date: Monday, 15 August, 2011, 10:16
>
> Does this help:
> http://dzenanz.wordpress.com/2011/04/05/qwidget-must-construct-a-qapplication-before-a-qpaintdevice/
>
> On Mon, Aug 15, 2011 at 09:09, Leonid Dulman <leonid_dulman at yahoo.co.uk> wrote:
>
> Hi to All
> In next Example
> #include "qmainwindow.h"
> #include "qapplication.h"
>
> #include <QVTKWidget.h>
> #include <QVTKApplication.h>
>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkTextSource.h>
> #include <vtkVectorText.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
>
> int main( int argc, char **argv )
> {
> QVTKApplication app(argc,argv);
> QMainWindow *mainWindow = new QMainWindow;
> mainWindow->setFixedSize(640,360);
>
> QVTKWidget *widget = new QVTKWidget;
> mainWindow->setCentralWidget(widget);
>
> vtkTextSource *text = vtkTextSource::New();
> text->SetText("Hello World!");
> text->BackingOff();
> vtkVectorText *vectorText = vtkVectorText::New();
> vectorText->SetText("QVTKWidget");
> vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New();
> textMapper->SetInput(text->GetOutput());
> vtkPolyDataMapper *vectorTextMapper = vtkPolyDataMapper::New();
> vectorTextMapper->SetInput(vectorText->GetOutput());
> vtkActor *textActor = vtkActor::New();
> textActor->SetMapper(textMapper);
> vtkActor *vectorTextActor = vtkActor::New();
> vectorTextActor->SetMapper(vectorTextMapper);
> vtkRenderer *renderer = vtkRenderer::New();
> renderer->SetBackground(0.4,0.6,0.8);
> renderer->AddActor(textActor);
> renderer->AddActor(vectorTextActor);
> vtkRenderWindow *renderWindow = vtkRenderWindow::New();
> renderWindow->AddRenderer(renderer);
> renderWindow->SetStereoTypeToDresden();
>
> widget->SetRenderWindow(renderWindow);
> mainWindow->show();
> app.aboutQt();
> return app.exec();
> }
>
> I have got massage "QWidget:Must construct a QApplication before a QPaintDevice" only in Windows 7 SP1, in Windows XP and linux I have no any problems
>
> My installation is
> Qt 4.7.3
> VTK 5.9.0 (from git)
> Thank you. Leonid
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorld.png
Type: image/png
Size: 12015 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110815/e9155d89/attachment.png>
More information about the Insight-users
mailing list