-
compile issue, syntax i guess, but can't find it
archiv.h
Code:
{
Q_OBJECT
public:
~Archives();
...
archiv.cpp
Code:
//****************************************************************
{
return model->data(idx.sibling(idx.row(), 0)).toString();
}
and menu.cpp
Code:
//****************************************************************
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.
-
Re: compile issue, syntax i guess, but can't find it
Edit: errr.. use operator "." and you need to also pass a QModelIndex.
Code:
QString s
= Archives_dlg.
getFileName(idx
);
-
Re: compile issue, syntax i guess, but can't find it
same with '.' : 180 C:\Qt\test\sms\menu.cpp expected primary-expression before "const"
my previous call is with "->"
-
Re: compile issue, syntax i guess, but can't find it
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.
-
Re: compile issue, syntax i guess, but can't find it
In C++, you access class members with operator "->" from a pointer, and with operator "." from an object.
You either:
Code:
Archives Archives_dlg(this);
Archives_dlg.blaa();
OR
Code:
Archives* Archives_dlg = new Archives(this);
Archives_dlg->blaa();
Notice the difference?
-
Re: compile issue, syntax i guess, but can't find it
archiv.h
Code:
public:
~Archives();
archiv.cpp
Code:
//****************************************************************
{
return model->data(idx.sibling(idx.row(), 0)).toString();
}
menu.cpp
Code:
//****************************************************************
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.
-
Re: compile issue, syntax i guess, but can't find it
Did you #include "archiv.h" in menu.cpp?
-
Re: compile issue, syntax i guess, but can't find it
yes it is a new action in the same class that :
this compiles and works
Code:
QString s
= Archives_dlg
->getFileName
(idx
);
this does not
just a new routine based on a click on the view
-
Re: compile issue, syntax i guess, but can't find it
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.
-
Re: compile issue, syntax i guess, but can't find it
menu.cpp
Code:
//****************************************************************
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);
-
Re: compile issue, syntax i guess, but can't find it
I declare it in the connect :
Code:
connect( qArchiv,
SIGNAL( clicked
( const QModelIndex &) ),
archiv.h
Code:
#ifndef ARCHIVES_H
#define ARCHIVES_H
#include <qdialog.h>
#include <QtCore>
#include <QtGui>
{
Q_OBJECT
public:
~Archives();
protected slots:
private:
void remplirArchiv();
};
#endif
Code:
//****************************************************************
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
}
}
only the second line which uses QModelIndex fails:
181 C:\Qt\test\sms\menu.cpp expected primary-expression before "const"
-
Re: compile issue, syntax i guess, but can't find it
should i post a zip with all my files ?
-
Re: compile issue, syntax i guess, but can't find it
So you want the return the selected item as a string?
archiv.h:
archiv.cpp:
Code:
{
QModelIndex idx
= qArchiv
->selectionModel
()->currentIndex
();
return model->data(idx.sibling(idx.row(), 0)).toString();
}
menu.cpp:
Code:
void ApplicationWindow::archives()
{
Archives Archives_dlg( this );
if ( Archives_dlg.exec() )
{
QString qS
= Archives_dlg.
getFileName();
// 181 }
}
-
Re: compile issue, syntax i guess, but can't find it
You shouldn't use any type names in the call. It should like this:
Code:
QString qS
= Archives_dlg.
getFileName(idx
);
-
Re: compile issue, syntax i guess, but can't find it
Code:
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.
-
Re: compile issue, syntax i guess, but can't find it
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)..
-
Re: compile issue, syntax i guess, but can't find it
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.