[vtkusers] vtkStringArray problem
Cory Quammen
cory.quammen at kitware.com
Wed Dec 3 10:25:55 EST 2014
Rich,
Hmm, I don't see anything obviously wrong with your code. I have
attached a sample program that creates a vtkStringArray like you are
doing and it runs fine.
Could you try running your code through a memory checker such as
valgrind to see if there might be memory errors elsewhere that
manifest in this section of the code?
Thanks,
Cory
On Wed, Dec 3, 2014 at 7:29 AM, mbcx9rb9 <richard.j.brown at live.co.uk> wrote:
> Cory,
>
> It is written in Qt but the first 4 lines of code create a list of DICOM
> filenames. The part in the for loop is the relevant bit, when I try to write
> in entry by entry into the vtkStringArray. I could just as easily comment
> out the lines:
>
> filenames->SetNumberOfValues(list.size());
> filenames->SetValue(i,temp.c_str());
>
> and uncomment the line:
>
> filenames->InsertNextValue(temp);
>
> however neither work. I have tried various combinations of insert temp as a
> vtkStdString etc. but to no avail.
>
> Cheers,
> Rich
>
>
> void MainWindow::listFiles(QString path)
>
> {
> // set path to user chosen folder
> QDir dir = QDir(path);
>
> // set filter to only search for dicom files
> QStringList filters;
> filters << "*.dcm";
> dir.setNameFilters(filters);
>
> // Create list of all *.dcm filenames
> QStringList list = dir.entryList();
>
> if (list.size() == 0) { QMessageToScreen("Error. No DICOM files found in
> this directory"); }
> else
> {
> // if there exist DICOM files in directory, create vector containing
> them all
> vtkSmartPointer<vtkStringArray> filenames =
> vtkSmartPointer<vtkStringArray>::New();
> filenames->SetNumberOfValues(list.size());
> filenames->SetName("List_of_Filenames");
> for (int i=0; i<list.size(); i++)
> {
> std::string temp = dir.absolutePath().toStdString() +
> "/" + list.at(i).toStdString();
> std::cout <<temp.c_str()<<std::endl;
>
> //to assign data use setnumberofvalues and setvalue or
> insertnextvalue
> filenames->SetValue(i,temp.c_str());
>
> //filenames->InsertNextValue(temp);
> }
>
> QMessageToScreen(QString::number(filenames->GetNumberOfValues()));
>
> // vktDICOMSorter is used to find out how many series exist in a
> directory
> //vtkSmartPointer<vtkDICOMSorter> sorter =
> vtkSmartPointer<vtkDICOMSorter>::New();
> //sorter->SetInputFileNames(filenames);
> //sorter->Update();
> }
> }
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/vtkStringArray-problem-tp5729638p5729646.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://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
project(StringArrayTest)
cmake_minimum_required(VERSION 2.8)
find_package(VTK COMPONENTS vtkCommonCore REQUIRED)
include(${VTK_USE_FILE})
#message(STATUS ${VTK_LIBRARIES})
add_executable(StringArrayTest StringArrayTest.cxx)
target_link_libraries(StringArrayTest ${VTK_LIBRARIES})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StringArrayTest.cxx
Type: text/x-c++src
Size: 540 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141203/72909e02/attachment.cxx>
More information about the vtkusers
mailing list