PDA

View Full Version : QList err : expected primary-expression before ‘)’ token



mkts
29th December 2010, 16:07
Hi all
Please for support and help
Thanks in advance!


my list in .h file

QList < FilmDoc > * pDocList;

void FilmApp::openDocumentFile (const char *file)
{
statusBar ()->message (tr ("Opening file..."));

QList <FilmDoc> doc = *pDocList;

// if this might help function has to check if file is already opened
// and if yes then setFocus to opened view
for ( int i = 0; i < doc.size (); ++i ) {
if ( doc.contains ( doc& ) == file ){// this line generate err

FilmView * view = doc->firstView ();
view->setFocus ();
return;
}
}
...
}

high_flyer
29th December 2010, 16:12
doc.contains ( doc& ) makes no sense.
you probably want:


if(doc.at(i) == file){
...
}

mkts
29th December 2010, 16:42
thx but this code is generating msg;

"error: no match for ‘operator==’ in ‘doc.QList<T>::at [with T = FilmDoc](i) == file’
candidates are: bool operator==(QBool, bool)
...
and much more of this
"

high_flyer
29th December 2010, 17:46
it means that FilmDoc has no '==' operator.
You will have to compare some property of FilmDoc to make sure you have the one you need.
If there is no such property, you will have to implement the '==' operator.
But you probably can get away with storing pointers, which you can compare, and they are unique per item.
QList<FilmDoc *> myList;

d_stranz
3rd January 2011, 01:16
if ( doc.contains ( doc& ) == file ){// this line generate err


This line makes no sense, as someone else pointed out. Even if you got the syntax right, it still makes no sense.

Assuming what you want is



if( doc.at(i) == file )


then what that line says is to compare a "FilmDoc" object (that's what is getting retrieved from the QList using the at() method) to a char * string. If your FilmDoc class doesn't have a



bool operator==( const char * ) const;


method, then this is what is generating your compile error.

You probably want code that looks something like this:



void FilmApp::openDocumentFile (const char *file)
{
statusBar ()->message (tr ("Opening file..."));

QList <FilmDoc> doc = *pDocList;

// if this might help function has to check if file is already opened
// and if yes then setFocus to opened view
for ( int i = 0; i < doc.size (); ++i ) {
const FileDoc & fileDoc = doc.at( i );
if (fileDoc.name() == file ) {
// But now this line will generate an error, because QList<T> doesn't have a "firstView()" method.
// You probably mean: FilmView * view = fileDoc.firstView() instead
FilmView * view = doc->firstView ();
view->setFocus ();
return;
}
}
...
}


Added after 7 minutes:

Sorry, I meant "FilmDoc", not "FileDoc" in line 10. Got confused comparing films and files.