PDA

View Full Version : Having Trouble Creating Classes



jstippey
17th March 2011, 14:35
Currently, I am trying to learn how to write more robust code that is more easily extendable. For this, I am trying to create a class that opens up TIFF images and performs some basic Image processing process ( find Max pixel etc...). I am using QT 3.1 (I know later versions support TIFF, but I am trying to learn here). I am using a open source library called libtiff. My basic layout is set up like this

TIFFImage.h


#ifndef TIFFIMAGE_H
#define TIFFIMAGE_H

#include<stdio.h>
#include<tiffio.h>
#include<tiff.h>
#include<tiffvers.h>

class QVariant;
class QString;

class TIFFImage
{
public:
TIFFImage();
~TIFFImage(); {}

private:
bool loadTIFF ( const QString fileNameTIFF, const char readWriteOption);
}
endif


TIFFImage.cpp


#include "tiffimage.h"
#include<stdio.h>
#include<tiffio.h>
#include<tiff.h>
#include<tiffvers.h>

TIFFImage::TIFFImage()

bool TIFFImage::loadTIFF(const QString fileNameTIFF, const char readWriteOption)
{
TIFF * tif = TIFFOpen(fileNameTIFF, readWriteOption);
if (tif==Null)
{
return false;
}
return true;
}
}


I then have a form I created with QT Designer that I want to call this class from. However when I try to compile I get a error in tiffimage.cpp
"error expected initializer before bool" from the line that loadTIFF function is implemented. I am sure I am making some simple mistake, but I haven't been able to figure it out. Any help would be appreciated.

Zlatomir
17th March 2011, 14:46
You have a typo in your .h file:

~TIFFImage(); {} //the ';' on this line
//it's recommended to move the implementation {} in the .cpp file

And also the constructor is not implemented (in the .cpp file):


TIFFImage::TIFFImage()

And also you load the imaga and after the loadTIFF function is executed you can't access it (and maybe you have a leak, check with the library documentation if you are supposed to delete the returned pointer (TIFF * tif)
You can move that pointer declaration to be a member of the class (not a local variable in the loadTIFF member function.

jstippey
17th March 2011, 15:22
For item 1, I double checked I don't have the ";" in there, I must have accidentally added when I pasted it in. Thank you for the catch in the cpp file, it is now making it to my function calls in the form1.ui.h file.