Results 1 to 5 of 5

Thread: Using template in constructors

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Using template in constructors

    Hi friends,

    I have a class that must pass as a parameter in the constructor pointer to a class that inherits from any QWidget. I'm trying to use the concept of templates for this, but I'm having difficulties. When compiling, I have the following error:

    undefined reference to `Report: Report (QWidget *, NFePrint *)

    The following snippet of code in classes involved:

    Qt Code:
    1. class Report: public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. template <typename Tx>
    6. Report(QWidget *parent = 0, Tx *widgetPrint = 0);
    7. .....
    8. }
    9.  
    10. template <typename Tx>
    11. Report::Report(QWidget *parent, Tx *widgetPrint)
    12. :QMainWindow(parent), currentZoom(100)
    13. {
    14. ui.setupUi(this);
    15. .......
    16. }
    17.  
    18. void MainWindow::showReport()
    19. {
    20. NFePrint *nfePrint = new NFePrint;
    21. Report *r = new Report(this, nfePrint);
    22. r->show();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Using template in constructors

    Why not use a template class Report?
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Using template in constructors

    Because I have other classes that I pass as a parameter in the constructor

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using template in constructors

    You can't have templates in classes containing Q_OBJECT macros.

  5. #5
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Using template in constructors

    OK, thanks for information.
    I'm was resolving problem writing the class for reuse the code.
    Thanks,

    Marcelo E. Geyer.

Similar Threads

  1. Replies: 2
    Last Post: 7th July 2008, 08:44
  2. specialization of a template method
    By darksaga in forum General Programming
    Replies: 3
    Last Post: 12th April 2008, 00:53
  3. qt 4.2.2 install in tru64 cxx
    By try to remember in forum Installation and Deployment
    Replies: 0
    Last Post: 30th March 2007, 07:43
  4. how to write a template function in a form..
    By nass in forum General Programming
    Replies: 7
    Last Post: 18th December 2006, 19:36
  5. problem using template
    By mickey in forum General Programming
    Replies: 6
    Last Post: 18th November 2006, 15:57

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.