<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body><div style="text-align: left;">Hello Matthias,<br><br>I have never used the QtSlotAdaptor but there is another simple way to do what u want.<br><br>You can use Qts signal-slot mechanism.<br><br>You need to create a class with the Q_OBJECT macro ,in a slot of this class put the itk functionality, create a QPushButton and an object of that class and connect the buttons signal clicked() to that slot.<br><br>#ifnded myclass_h<br>#define myclass_h<br><br>#include "itkMedianImageFilter.h"<br>#include "qstring.h"<br>#include "itkImage.h"<br>#include "qfiledialog.h"<br><br>class myclass<br>{<br>Q_OBJECT<br>typedef itk::Image<short int ,2>InputImageType;<br>typedef itk::Image<short int ,2>OutputImageType;<br><br>public:<br> <br>public slots:<br> void myslot()<br> {<br> typedef itk::ImageFileReader<InputImageType> readertype;<br> readertype::Pointer reader=readertype::New();<br> <br> typedef itk::ImageFileWriter<OutputImageType> writertype;<br> writertype::Pointer writer=writertype::New();<br> <br> typedef itk::MedianImageFilter <InputImageType, OutputImageType>FilterType;<br> FilterType::Pointer filter=FilterType::New()<br> <br> QString filename;<br> filename=QFileDialog::getOpenFileName();<br> reader->SetFileName(filename.latin1());<br> <br> filename=QFileDialog::getSaveFileName();<br> writer->SetFileName(filename.latin1()); <br><br> filter->SetInput(reader->GetOutput());<br> writer->SetInput(filter->GetOutput());<br> filter->Update();<br> }<br><br>};<br>#endif<br></div><br>and in ur main.ccp file: <br>(i use qt 3.2.1 , it would be a little different in Qt 4 )<br><br>#include <qapplication.h><br>#include "myclass.h"<br>#include <qpushbutton.h><br><br>int main( int argc, char **argv )<br>{<br>QApplication a( argc, argv );<br>QPushButton button;<br>a.setMainWidget(&button); <br>myclass median;<br><br>connect(button,SIGNAL(clicked()),median,SLOT(myslot()));<br><br>button.show();<br>return a.exec();<br>}<br><br>Note that all objects created with New() will be deleted at the end of myslot(). If u dont want that u should declare a smart pointer in the header file:<br><br>typedef itk::ImageFileReader<InputImageType> readertype;<br>readertype::Pointer reader=NULL;<br><br>and initialize it inside myslot()<br>readertype::New();<br><br>Also note that since myclass is now a Q_OBJECT it needs moc and in your CMakeLists.txt you should add<br><br>SET(myProject_MOC_SRCS<br> myclass.h<br> )<br><br>Hope the above works havent tried it.<br><br>Plato.<br><br><hr id="stopSpelling">> Date: Sat, 9 Dec 2006 14:35:28 +0100<br>> From: mebert@uni-koblenz.de<br>> To: insight-users@itk.org<br>> Subject: [Insight-users] Qt itk filter<br>> <br>> Hi everyone,<br>> <br>> i am new to this mailing list, so first of all: hello :)<br>> <br>> i try to get a simple qt-itk example to work, but i got some problems<br>> launching my filter using a qt button.<br>> i dont know if its the right way i try to do this:<br>> <br>> 1.) i create a median filter (according to the example in<br>> ItkSoftwareGuide):<br>> <br>> typedef itk::MedianImageFilter <InputImageType, OutputImageType><br>> FilterType;<br>> FilterType::Pointer filter = FilterType::New();<br>> <br>> 2.) i create a simple qt-button:<br>> <br>> QPushButton medianFilterButton("Median Filter", &mainWidget);<br>> medianFilterButton.setGeometry(horizontalPosition, 20, buttonWidth,<br>> buttonHeight);<br>> <br>> 3.) i use the qt-itk-adaptor (guess this is wrong):<br>> <br>> typedef itk::QtSlotAdaptor<FilterType> SlotAdaptorType;<br>> SlotAdaptorType slotAdaptor;<br>> slotAdaptor.SetCallbackFunction(filter, & FilterType::Update);<br>> QObject::connect(&medianFilterButton, SIGNAL(clicked()), &slotAdaptor,<br>> SLOT(Slot()));<br>> <br>> so here are my questions:<br>> <br>> how do i launch my median filter using a qt-button? i need to set the<br>> input for the filter and the writer doing something like this:<br>> <br>> filter->SetInput(reader->GetOutput());<br>> writer->SetInput(filter->GetOutput());<br>> <br>> but thats not the way i want to do it. i just want this to happen after<br>> pushing the button.<br>> can anyone explain me how i figure out which filter has which slots? i<br>> am a bit confused about this ...<br>> <br>> if u need more code to understand what i mean, please let me know!<br>> <br>> thanks for help,<br>> <br>> Matthias<br>> _______________________________________________<br>> Insight-users mailing list<br>> Insight-users@itk.org<br>> http://www.itk.org/mailman/listinfo/insight-users<br><br /><hr />Call friends with PC-to-PC calling -- FREE <a href='http://get.live.com/messenger/overview' target='_new'>Try it now!</a></body>
</html>