[vtkusers] Example VTK with Qt
Jothybasu Selvaraj
jothybasu at gmail.com
Fri Aug 17 09:00:27 EDT 2012
In both openFile() and saveFile()
filename is out of scope. you shouls be using fileName.toLatin1() instead.
Jothy
On Fri, Aug 17, 2012 at 1:57 PM, Agata Krasoń <agatakrason at gmail.com> wrote:
> Hi,
>
> I have one more question to You a propos de qt:
> I created qui (I send You screen).
> I made 2 slots openFile() and saveFile()
>
> I can't call well all .
>
> For the moment Could You look at this code ?
> Principally on constructor : I think that it is something wrong with it..
>
>
> #include "ui_SimpleViewUI.h"
> #include "SimpleViewUI.h"
>
> #include <vtkPolyDataMapper.h>
> #include <vtkRenderer.h>
> #include <vtkPolyData.h>
> #include <vtkRenderWindow.h>
> #include <vtkSphereSource.h>
> #include <vtkXMLPolyDataReader.h>
> #include <vtkXMLPolyDataWriter.h>
> #include "vtkSmartPointer.h"
>
> #include <QString>
> #include <QFileDialog>
> #include <QMessageBox>
> #include <QFile>
>
> // Constructor
> SimpleView::SimpleView()
> {
> this->ui = new Ui_SimpleView;
> this->ui->setupUi(this);
>
>
>
> // VTK Renderer
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
>
> // VTK/Qt wedded
> this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
>
> // vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
>
> vtkPolyData* polydata = vtkPolyData::New();
> polydata = reader->GetOutput();
>
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInput(polydata);
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> renderer->AddActor(actor);
>
>
> // Set up action signals and slots
> connect(this->ui->actionExit, SIGNAL(triggered()), this,
> SLOT(slotExit()));
> connect(this->ui->openButton, SIGNAL(clicked()), this, SLOT(openFile()));
> connect(this->ui->saveButton, SIGNAL(clicked()), this, SLOT(saveFile()));
>
> setWindowTitle("Display Model - Mesh - Surface");
>
>
> }
>
> void SimpleView::slotExit()
> {
> qApp->exit();
> }
>
> void SimpleView::openFile()
> {
>
> QString fileName = QFileDialog::getOpenFileName(this, tr("Open file with
> model/mesh"), "", tr("files (*.vtp);;All Files (*)"));
>
> std::string filename = fileName.toLatin1();
> vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
> reader->SetFileName(filename.c_str());
> reader->Update();
>
>
> }
>
> void SimpleView::saveFile()
> {
> // std::cout <<" save file "<<std::endl;
> QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "
> ",tr("Images/models (*.vtp)"));
>
> std::string filename = fileName.toLatin1();
> vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
> writer->SetInputConnection(reader->GetOutputPort());
> writer->SetFileName(filename.c_str());
> writer->Write();
>
>
>
>
> }
>
>
> SimpleView::~SimpleView(){}
>
> I would appreciate for any help please.
>
>
> agata
>
> 2012/8/17 Jothybasu Selvaraj <jothybasu at gmail.com>
>
>> And post your code, it seems to that you are not seeting the file name
>> properly.
>>
>>
>>
>> On Fri, Aug 17, 2012 at 12:36 PM, agatte <agatakrason at gmail.com> wrote:
>>
>>> Hi ;)
>>>
>>> I launch program. I can't open&load a vtp file and save.
>>> I received error info :
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\IO\vtkXMLReader.cxx, line 204
>>> vtkXMLPolyDataReader (07809840): File name not specified
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\Filtering\vtkExecutive.cxx, line 756
>>> vtkStreamingDemandDrivenPipeline (0780AFF0): Algorithm
>>> vtkXMLPolyDataReader(07809840) returned failure for request:
>>> vtkInformation
>>> (0783C218)
>>> Debug: Off
>>> Modified Time: 1556
>>>
>>> Reference Count: 1
>>> Registered Events: (none)
>>> Request: REQUEST_INFORMATION
>>> FORWARD_DIRECTION: 0
>>> ALGORITHM_AFTER_FORWARD: 1
>>> FROM_OUTPUT_PORT: 0
>>>
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\IO\vtkXMLReader.cxx, line 204
>>> vtkXMLPolyDataReader (07809840): File name not specified
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\Filtering\vtkExecutive.cxx, line 756
>>> vtkStreamingDemandDrivenPipeline (0780AFF0): Algorithm
>>> vtkXMLPolyDataReader(07809840) returned failure for request:
>>> vtkInformation
>>> (0782D208)
>>> Debug: Off
>>> Modified Time: 1687
>>>
>>> Reference Count: 1
>>> Registered Events: (none)
>>> Request: REQUEST_DATA
>>> FORWARD_DIRECTION: 0
>>> ALGORITHM_AFTER_FORWARD: 1
>>> FROM_OUTPUT_PORT: 0
>>>
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\IO\vtkXMLReader.cxx, line 219
>>> vtkXMLPolyDataReader (0782C818): Error opening file XM€
>>>
>>>
>>> ERROR: In C:\VTK\VTK-5.8\sources\Filtering\vtkExecutive.cxx, line 756
>>> vtkStreamingDemandDrivenPipeline (078302F0): Algorithm
>>> vtkXMLPolyDataReader(0782C818) returned failure for request:
>>> vtkInformation
>>> (0C67E420)
>>> Debug: Off
>>> Modified Time: 1976
>>>
>>> Reference Count: 1
>>> Registered Events: (none)
>>> Request: REQUEST_INFORMATION
>>> FORWARD_DIRECTION: 0
>>> ALGORITHM_AFTER_FORWARD: 1
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://vtk.1045678.n5.nabble.com/Example-VTK-with-Qt-Load-and-Save-VTP-file-tp5715374p5715378.html
>>>
>>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> 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
>>>
>>
>>
>>
>> --
>> Jothybasu Selvaraj
>> PhD Student
>> University of Liverpool
>> UK
>>
>>
>
--
Jothybasu Selvaraj
PhD Student
University of Liverpool
UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120817/cbf16255/attachment.htm>
More information about the vtkusers
mailing list