PDA

View Full Version : no matching function error



arpspatel
16th October 2009, 04:16
int counter = 0 ;
while(!n.isNull()) {
QDomElement e = n.toElement();
if(!e.isNull()) {
if(e.tagName() != "movie"){
return false;
}
}
QDomNode c = e.firstChild();
while(!c.isNull()){
QDomElement k = c.toElement();
tabmovies->insertRow(1);
if(k.tagName() == "name"){tabmovies->setItem(counter,0,QTableWidgetItem(k.text()));}
if(k.tagName() == "weburl"){ tabmovies->setItem(counter,1,QTableWidgetItem(k.text())); }
if(k.tagName() == "year"){tabmovies->setItem(counter,2,QTableWidgetItem(k.text()));}
if(k.tagName() == "image"){tabmovies->setItem(counter,3,QTableWidgetItem(k.text()));}
if(k.tagName() == "quality"){tabmovies->setItem(counter,4,QTableWidgetItem(k.text()));}
if(k.tagName() == "onhdd"){tabmovies->setItem(counter,5,QTableWidgetItem(k.text()));}
if(k.tagName() == "path"){tabmovies->setItem(counter,6,QTableWidgetItem(k.text()));}
c = c.nextSibling();
}
counter++;
n = n.nextSibling();
}
return true;


I am writing a library for my movies collection which reads in xml data and stores into a tablewidget for gui/cmdline part. I have a strange error, although i specify that i want to use integer only, the compiler interprets as int& and give me error as below.


qcldata.cpp: In member function ‘bool qcldata::processdata()’:
qcldata.cpp:42: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:43: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:44: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:45: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:46: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:47: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
qcldata.cpp:48: error: no matching function for call to ‘QTableWidget::setItem(int&, int, QTableWidgetItem)’
/usr/include/QtGui/qtablewidget.h:242: note: candidates are: void QTableWidget::setItem(int, int, QTableWidgetItem*)
make: *** [.moc_obj/qcldata.o] Error 1

could someone please help me out with error, i think it is something simple and i am missing it..

Thanks
Arpit

jord
16th October 2009, 06:15
The 3rd parameter to QTableWidget::setItem() needs to be a pointer to a QTableWidgetItem. You need to create the QTableWidgetItem on the heap using new, instead of on the stack.

eg:

if(k.tagName() == "name"){tabmovies->setItem(counter,0,new QTableWidgetItem(k.text()));}

Lykurg
16th October 2009, 08:19
Hi,

better use
if(k.tagName() == "name"){tabmovies->setItem(counter,0,new QTableWidgetItem(k.text()));}
else if(k.tagName() == "weburl"){ tabmovies->setItem(counter,1,new QTableWidgetItem(k.text())); }
else if(k.tagName() == "year"){tabmovies->setItem(counter,2,new QTableWidgetItem(k.text()));}

it will make your application faster. Further insertRow is the "wrong" function for you because you always add a empty row at 1 but set the content for the last line. So you probably want use QTableWidget::setRowCount().

arpspatel
16th October 2009, 16:44
The 3rd parameter to QTableWidget::setItem() needs to be a pointer to a QTableWidgetItem. You need to create the QTableWidgetItem on the heap using new, instead of on the stack.

eg:

if(k.tagName() == "name"){tabmovies->setItem(counter,0,new QTableWidgetItem(k.text()));}

Thanks man worked instantly... i know i was missing someting simple.. thanks again.

arpspatel
16th October 2009, 16:47
Hi,

better use
if(k.tagName() == "name"){tabmovies->setItem(counter,0,new QTableWidgetItem(k.text()));}
else if(k.tagName() == "weburl"){ tabmovies->setItem(counter,1,new QTableWidgetItem(k.text())); }
else if(k.tagName() == "year"){tabmovies->setItem(counter,2,new QTableWidgetItem(k.text()));}

it will make your application faster. Further insertRow is the "wrong" function for you because you always add a empty row at 1 but set the content for the last line. So you probably want use QTableWidget::setRowCount().

Thanks.. i have a huge xml file, so takes abt 2 mins to read.. but this was quicker