Results 1 to 17 of 17

Thread: compile issue, syntax i guess, but can't find it

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default compile issue, syntax i guess, but can't find it

    archiv.h
    Qt Code:
    1. class Archives : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Archives( QWidget *parent = 0 );
    7. ~Archives();
    8. QString getFileName( const QModelIndex &);
    9. ...
    To copy to clipboard, switch view to plain text mode 
    archiv.cpp
    Qt Code:
    1. //****************************************************************
    2. QString Archives::getFileName( const QModelIndex & idx )
    3. {
    4. return model->data(idx.sibling(idx.row(), 0)).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 

    and menu.cpp
    Qt Code:
    1. //****************************************************************
    2. void ApplicationWindow::archives()
    3. {
    4. Archives Archives_dlg( this );
    5. if ( Archives_dlg.exec() )
    6. {
    7. QString s = Archives_dlg->getFileName( const QmodelIndex & idx);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: compile issue, syntax i guess, but can't find it

    Edit: errr.. use operator "." and you need to also pass a QModelIndex.

    Qt Code:
    1. QModelIndex idx = ....
    2. QString s = Archives_dlg.getFileName(idx);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 29th March 2006 at 14:39.

  3. The following user says thank you to jpn for this useful post:

    incapacitant (29th March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 "->"

  5. #4
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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:
    Qt Code:
    1. Archives Archives_dlg(this);
    2. Archives_dlg.blaa();
    To copy to clipboard, switch view to plain text mode 
    OR
    Qt Code:
    1. Archives* Archives_dlg = new Archives(this);
    2. Archives_dlg->blaa();
    To copy to clipboard, switch view to plain text mode 

    Notice the difference?

  7. The following user says thank you to jpn for this useful post:

    incapacitant (29th March 2006)

  8. #6
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compile issue, syntax i guess, but can't find it

    archiv.h
    Qt Code:
    1. public:
    2. Archives( QWidget *parent = 0 );
    3. ~Archives();
    4. QString getFileName( const QModelIndex &);
    To copy to clipboard, switch view to plain text mode 

    archiv.cpp
    Qt Code:
    1. //****************************************************************
    2. QString Archives::getFileName( const QModelIndex & idx )
    3. {
    4. return model->data(idx.sibling(idx.row(), 0)).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 

    menu.cpp
    Qt Code:
    1. //****************************************************************
    2. void ApplicationWindow::archives()
    3. {
    4. Archives Archives_dlg( this );
    5. if ( Archives_dlg.exec() )
    6. {
    7. QString s = Archives_dlg.getFileName(idx);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 


    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.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: compile issue, syntax i guess, but can't find it

    Did you #include "archiv.h" in menu.cpp?

  10. The following user says thank you to wysota for this useful post:

    incapacitant (29th March 2006)

  11. #8
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compile issue, syntax i guess, but can't find it

    yes it is a new action in the same class that :
    Qt Code:
    1. QStringList ret = Destinataires_dlg->getDestList();
    To copy to clipboard, switch view to plain text mode 
    this compiles and works
    Qt Code:
    1. QString s = Archives_dlg->getFileName(idx);
    To copy to clipboard, switch view to plain text mode 
    this does not


    just a new routine based on a click on the view

  12. #9
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  13. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: compile issue, syntax i guess, but can't find it

    menu.cpp
    Qt Code:
    1. //****************************************************************
    2. void ApplicationWindow::archives()
    3. {
    4. Archives Archives_dlg( this );
    5. if ( Archives_dlg.exec() )
    6. {
    7. QString s = Archives_dlg.getFileName(idx);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    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);

  14. The following user says thank you to jpn for this useful post:

    incapacitant (29th March 2006)

  15. #11
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compile issue, syntax i guess, but can't find it

    I declare it in the connect :
    Qt Code:
    1. connect( qArchiv, SIGNAL( clicked( const QModelIndex &) ),
    2. this, SLOT( selectmsg( const QModelIndex &) ) );
    To copy to clipboard, switch view to plain text mode 
    archiv.h
    Qt Code:
    1. #ifndef ARCHIVES_H
    2. #define ARCHIVES_H
    3.  
    4. #include <qdialog.h>
    5.  
    6. #include <QtCore>
    7. #include <QtGui>
    8.  
    9. class QTreeView;
    10.  
    11. class Archives : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Archives( QWidget *parent = 0 );
    17. ~Archives();
    18.  
    19. QString getFileName( const QModelIndex & );
    20.  
    21. protected slots:
    22. void selectmsg( const QModelIndex & );
    23.  
    24.  
    25. private:
    26. QTreeView *qArchiv;
    27. QPushButton *pbOk;
    28.  
    29. void addArchiv( QString sDate, QString sDest, QString sMsg );
    30. void remplirArchiv();
    31.  
    32. };
    33.  
    34. #endif
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. //****************************************************************
    2. void ApplicationWindow::archives()
    3. {
    4. Archives Archives_dlg( this );
    5. if ( Archives_dlg.exec() )
    6. {
    7. QStringList ret = Destinataires_dlg->getDestList();
    8. QString qS = Archives_dlg.getFileName(const QModelIndex idx); // 181
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

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

  16. #12
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compile issue, syntax i guess, but can't find it

    should i post a zip with all my files ?

  17. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: compile issue, syntax i guess, but can't find it

    So you want the return the selected item as a string?

    archiv.h:
    Qt Code:
    1. public:
    2. QString getFileName();
    To copy to clipboard, switch view to plain text mode 

    archiv.cpp:
    Qt Code:
    1. QString Archives::getFileName()
    2. {
    3. QModelIndex idx = qArchiv->selectionModel()->currentIndex();
    4. return model->data(idx.sibling(idx.row(), 0)).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 

    menu.cpp:
    Qt Code:
    1. void ApplicationWindow::archives()
    2. {
    3. Archives Archives_dlg( this );
    4. if ( Archives_dlg.exec() )
    5. {
    6. QStringList ret = Destinataires_dlg->getDestList();
    7. QString qS = Archives_dlg.getFileName(); // 181
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  18. The following user says thank you to jpn for this useful post:

    incapacitant (29th March 2006)

  19. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: compile issue, syntax i guess, but can't find it

    Qt Code:
    1. QString qS = Archives_dlg.getFileName(const QModelIndex idx);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. QString qS = Archives_dlg.getFileName(idx);
    To copy to clipboard, switch view to plain text mode 

  20. #15
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compile issue, syntax i guess, but can't find it

    Qt Code:
    1. QString qS = Archives_dlg.getFileName();
    To copy to clipboard, switch view to plain text mode 

    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.

Similar Threads

  1. qtgui4.dll error in visual c++ 2005
    By Comptrol in forum Installation and Deployment
    Replies: 33
    Last Post: 19th June 2008, 07:18
  2. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  3. Access to PostgreSQL DB on a linux server
    By rmagro in forum Qt Programming
    Replies: 28
    Last Post: 13th March 2008, 09:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.