QList err : expected primary-expression before ‘)’ token
Hi all
Please for support and help
Thanks in advance!
Code:
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;
}
}
...
}
Re: QList err : expected primary-expression before ‘)’ token
doc.contains ( doc& ) makes no sense.
you probably want:
Code:
if(doc.at(i) == file){
...
}
Re: QList err : expected primary-expression before ‘)’ token
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
"
Re: QList err : expected primary-expression before ‘)’ token
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;
Re: QList err : expected primary-expression before ‘)’ token
Code:
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
Code:
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
Code:
bool operator==( const char * ) const;
method, then this is what is generating your compile error.
You probably want code that looks something like this:
Code:
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.