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:
Code:
{
Q_OBJECT
public:
template <typename Tx>
Report
(QWidget *parent
= 0, Tx
*widgetPrint
= 0);
.....
}
template <typename Tx>
Report
::Report(QWidget *parent, Tx
*widgetPrint
){
ui.setupUi(this);
.......
}
void MainWindow::showReport()
{
NFePrint *nfePrint = new NFePrint;
Report *r = new Report(this, nfePrint);
r->show();
}
Thanks,
Marcelo E. Geyer
Re: Using template in constructors
Why not use a template class Report?
Re: Using template in constructors
Because I have other classes that I pass as a parameter in the constructor
Re: Using template in constructors
You can't have templates in classes containing Q_OBJECT macros.
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.