PDA

View Full Version : No Match for Call



Atomic_Sheep
29th April 2012, 10:56
Hi, I've got the following code:

file1.h


#include "file2.h"
#include <QString>

struct ChartProperties
{
QString yvar;
};

file1.cpp


ChartProperties chart1;
if(VariablePresent(chart1.yvar) //etc

file 2.h


#include "file1.h"
#include <QFile>

bool VariablesPresent(QString userVariable);

file2.cpp


bool VariablesPresent(QString userVariable)
{
QFile cVariableEquivalents(//actual system path);
if(!cVariableEquivalents().exists())
//etc
}

I may have missed one or two includes here or there... I've got them in my program, so the problem isn't with the includes I don't think.

The error that I get at compile is:


no match for call to '(QFile) ()'

Any ideas on what I'm doing wrong?

stampede
29th April 2012, 13:59
Can you show unmodified part of code that gives you this compilation error ?

norobro
29th April 2012, 20:12
no match for call to '(QFile) ()'
The problem is in file2.cpp line #4: cVariableEquivalents()

ChrisW67
29th April 2012, 23:13
Line 3 of file2.cpp is in error. You have commented out the closing bracket so that once the pre-processor is finished with it the code reads:


bool VariablesPresent(QString userVariable)
{
QFile cVariableEquivalents(
if(!cVariableEquivalents().exists())

}

which clearly makes no sense. The brackets in that line are unnecessary anyway.

Also, the function is called VariablesPresent() but you try to call VariablePresent(), which will not compile either.

Atomic_Sheep
2nd May 2012, 10:36
Ok, here's the unmodified version well excerpts at least:

comparison.h


#include <QMainWindow>
#include <QFile>
#include <QDir>
#include <QString>
#include <QTextStream>
#include <QMessageBox>
#include "ui_comparison.h"
#include "filemanager.h"

public:
struct ChartProperties
{
QString yAxisVariable;
QString xAxisVariable;
};


comparison.cpp


#include "comparison.h"

if(VariablesPresent(sChart1.yAxisVariable) && VariablesPresent(sChart1.xAxisVariable))

P.S. the && part wasn't included when I tried to compile it, I've added it later on top of the error and currently am just waiting to get this error fixed to see if this && part is going to cause problems later on in the code.

filemanager.h


#include <QFile>
#include <QDir>
#include <QString>
#include <comparison.h>
#include <QTextStream>

bool VariablesPresent(QString userVariable);

filemanager.cpp


#include "filemanager.h"

bool VariablesPresent(QString userVariable)
{
QFile cVariableEquivalents("/*directory*/");
if(!cVariableEquivalents().exists())

etc...

P.P.S. I'm not sure if bool is what I need but I'm using it for now, might change the function later on.

ChrisW67
2nd May 2012, 23:14
The problem is still, as norobro pointed out earlier, with line 6 of filemanager.cpp (formerly file2.cpp line 4). You are trying to call QFile::operator() and it doesn't exist, which is precisely what the compiler is telling you. The line should read:


...
if(!cVariableEquivalents.exists())
...

but it will only do something sensible if line 5 actually contains something likely to be a file name.

Atomic_Sheep
3rd May 2012, 10:16
OOOOOH, thanks, simple fix... I just had to remove the () brackets from all subsequent uses and now it's all good, thanks.