Results 1 to 3 of 3

Thread: Having Trouble Creating Classes

  1. #1
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Having Trouble Creating Classes

    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
    Qt Code:
    1. #ifndef TIFFIMAGE_H
    2. #define TIFFIMAGE_H
    3.  
    4. #include<stdio.h>
    5. #include<tiffio.h>
    6. #include<tiff.h>
    7. #include<tiffvers.h>
    8.  
    9. class QVariant;
    10. class QString;
    11.  
    12. class TIFFImage
    13. {
    14. public:
    15. TIFFImage();
    16. ~TIFFImage(); {}
    17.  
    18. private:
    19. bool loadTIFF ( const QString fileNameTIFF, const char readWriteOption);
    20. }
    21. endif
    To copy to clipboard, switch view to plain text mode 

    TIFFImage.cpp
    Qt Code:
    1. #include "tiffimage.h"
    2. #include<stdio.h>
    3. #include<tiffio.h>
    4. #include<tiff.h>
    5. #include<tiffvers.h>
    6.  
    7. TIFFImage::TIFFImage()
    8.  
    9. bool TIFFImage::loadTIFF(const QString fileNameTIFF, const char readWriteOption)
    10. {
    11. TIFF * tif = TIFFOpen(fileNameTIFF, readWriteOption);
    12. if (tif==Null)
    13. {
    14. return false;
    15. }
    16. return true;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. The following 2 users say thank you to jstippey for this useful post:


  3. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Having Trouble Creating Classes

    You have a typo in your .h file:
    Qt Code:
    1. ~TIFFImage(); {} //the ';' on this line
    2. //it's recommended to move the implementation {} in the .cpp file
    To copy to clipboard, switch view to plain text mode 
    And also the constructor is not implemented (in the .cpp file):
    Qt Code:
    1. TIFFImage::TIFFImage()
    To copy to clipboard, switch view to plain text mode 
    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.

  4. The following 3 users say thank you to Zlatomir for this useful post:

    jstippey (17th March 2011)

  5. #3
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Having Trouble Creating Classes

    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.

  6. The following 2 users say thank you to jstippey for this useful post:


Similar Threads

  1. Replies: 2
    Last Post: 2nd November 2011, 03:08
  2. Trouble with creating custom class
    By jstippey in forum Qt Programming
    Replies: 9
    Last Post: 12th January 2011, 14:08
  3. construction of classes within classes
    By mobucl in forum Newbie
    Replies: 8
    Last Post: 10th January 2011, 13:51
  4. Replies: 0
    Last Post: 4th November 2010, 14:51
  5. creating a dylib for a plugin with external classes
    By themolecule in forum Qt Programming
    Replies: 4
    Last Post: 23rd July 2008, 14:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.