PDA

View Full Version : compile issue, syntax i guess, but can't find it



incapacitant
29th March 2006, 15:20
archiv.h


class Archives : public QDialog
{
Q_OBJECT

public:
Archives( QWidget *parent = 0 );
~Archives();
QString getFileName( const QModelIndex &);
...

archiv.cpp


//************************************************** **************
QString Archives::getFileName( const QModelIndex & idx )
{
return model->data(idx.sibling(idx.row(), 0)).toString();
}


and menu.cpp


//************************************************** **************
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QString s = Archives_dlg->getFileName( const QmodelIndex & idx);
}
}

and the compiler says :
QString s = Archives_dlg->getFileName( const QmodelIndex & idx);
180 C:\Qt\test\sms\menu.cpp base operand of `->' has non-pointer type `Archives'

in the procedure above I make a similar call with (apparently the same syntax) and it works, so I don't know.

jpn
29th March 2006, 15:27
Edit: errr.. use operator "." and you need to also pass a QModelIndex.



QModelIndex idx = ....
QString s = Archives_dlg.getFileName(idx);

incapacitant
29th March 2006, 15:36
same with '.' : 180 C:\Qt\test\sms\menu.cpp expected primary-expression before "const"

my previous call is with "->"

incapacitant
29th March 2006, 16:06
QString s = Archives_dlg->getFileName(idx);
180 C:\Qt\test\sms\menu.cpp base operand of `->' has non-pointer type `Archives'

getFileName is a public function of class Archives.

Just like another instance in the code where this time it is a public function of another class.
I cannot see any difference in the way I do it.

jpn
29th March 2006, 16:16
In C++, you access class members with operator "->" from a pointer, and with operator "." from an object.

You either:


Archives Archives_dlg(this);
Archives_dlg.blaa();

OR


Archives* Archives_dlg = new Archives(this);
Archives_dlg->blaa();

Notice the difference?

incapacitant
29th March 2006, 16:56
archiv.h


public:
Archives( QWidget *parent = 0 );
~Archives();
QString getFileName( const QModelIndex &);


archiv.cpp


//************************************************** **************
QString Archives::getFileName( const QModelIndex & idx )
{
return model->data(idx.sibling(idx.row(), 0)).toString();
}


menu.cpp


//************************************************** **************
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QString s = Archives_dlg.getFileName(idx);
}
}



compiler
QString s = Archives_dlg.getFileName(idx);
180 C:\Qt\test\sms\menu.cpp no matching function for call to `Archives::getFileName(QModelIndex*&)'

It's is parameter type wrong somewhere. But I have a similar piece of code that works.
I am lost.

wysota
29th March 2006, 17:11
Did you #include "archiv.h" in menu.cpp?

incapacitant
29th March 2006, 17:14
yes it is a new action in the same class that :


QStringList ret = Destinataires_dlg->getDestList();

this compiles and works


QString s = Archives_dlg->getFileName(idx);

this does not


just a new routine based on a click on the view

incapacitant
29th March 2006, 19:12
when i remove the qmodelindex parameter from all sides (.h.cpp) it compiles, so it comes from the qmodelindex which is not passed correctly and as i said i don't understand.

jpn
29th March 2006, 20:18
menu.cpp


//************************************************** **************
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QString s = Archives_dlg.getFileName(idx);
}
}

Where do you declare that idx-variable?

Dunno if compilers even care about this, but you are also missing parameter name in archiv.h:
QString getFileName( const QModelIndex & idx);

incapacitant
29th March 2006, 20:25
I declare it in the connect :


connect( qArchiv, SIGNAL( clicked( const QModelIndex &) ),
this, SLOT( selectmsg( const QModelIndex &) ) );

archiv.h


#ifndef ARCHIVES_H
#define ARCHIVES_H

#include <qdialog.h>

#include <QtCore>
#include <QtGui>

class QAbstractItemModel;
class QTreeView;
class QModelIndex;

class Archives : public QDialog
{
Q_OBJECT

public:
Archives( QWidget *parent = 0 );
~Archives();

QString getFileName( const QModelIndex & );

protected slots:
void selectmsg( const QModelIndex & );


private:
QAbstractItemModel *model;
QTreeView *qArchiv;
QPushButton *pbOk;

void addArchiv( QString sDate, QString sDest, QString sMsg );
void remplirArchiv();

};

#endif





//************************************************** **************
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QStringList ret = Destinataires_dlg->getDestList();
QString qS = Archives_dlg.getFileName(const QModelIndex idx); // 181
}
}


only the second line which uses QModelIndex fails:
181 C:\Qt\test\sms\menu.cpp expected primary-expression before "const"

incapacitant
29th March 2006, 20:31
should i post a zip with all my files ?

jpn
29th March 2006, 21:14
So you want the return the selected item as a string?

archiv.h:


public:
QString getFileName();


archiv.cpp:


QString Archives::getFileName()
{
QModelIndex idx = qArchiv->selectionModel()->currentIndex();
return model->data(idx.sibling(idx.row(), 0)).toString();
}


menu.cpp:


void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QStringList ret = Destinataires_dlg->getDestList();
QString qS = Archives_dlg.getFileName(); // 181
}
}

wysota
29th March 2006, 21:16
QString qS = Archives_dlg.getFileName(const QModelIndex idx);

You shouldn't use any type names in the call. It should like this:


QString qS = Archives_dlg.getFileName(idx);

incapacitant
29th March 2006, 21:17
QString qS = Archives_dlg.getFileName();


compiler errors :
181 C:\Qt\test\sms\menu.cpp no matching function for call to `Archives::getFileName()'
note C:\Qt\test\sms\archiv.h:21 candidates are: QString Archives::getFileName(const QModelIndex&)
from .h declaration i suppose

I need this index it is the row that the user clicked on on the view. i cannot remove it everywhere.

jpn
29th March 2006, 21:25
Check carefully all the pieces of code I gave you (escpecially archiv.cpp).
It asks the current index from the view and returns it's data, there is no need to keep track of clicked items.. And you didn't store that clicked item anywhere anyway (and neither should you store model indexes, you are advised to use QPersistentModelIndex if you really need to)..

incapacitant
29th March 2006, 21:32
Thank you for your samples code, I did not see first about the IMPORTANT changes you had made. Now the slot is activated and I should be able to use it.