Results 1 to 6 of 6

Thread: Wrong function according to parameters is taken

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Wrong function according to parameters is taken

    Hi,

    in my own model I have:
    Qt Code:
    1. QVariant data(const QModelIndex &index, int role) const;
    2. QVariant data(const QModelIndex &index, BibtexGlobal::SearchFilter role) const;
    3. // BibtexGlobal::SearchFilter is an enum
    To copy to clipboard, switch view to plain text mode 
    And in an other class I call:
    Qt Code:
    1. QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
    2. QHash<BibtexGlobal::SearchFilter, QRegExp*>::const_iterator i = m_filter.constBegin();
    3. while (i != m_filter.constEnd())
    4. {
    5. qWarning() << sourceModel()->data(index, i.key());
    6. ++i;
    7. }
    To copy to clipboard, switch view to plain text mode 

    But although i.key() is BibtexGlobal::SearchFilter the function data(const QModelIndex &index, int role) is called. Why? Is int and enum for the compiler the same?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Wrong function according to parameters is taken

    A pure enum is a simple signed int, according to the C and C++ standard.
    Unless you make a "typedef enum", both functions will be the same for your compiler.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Wrong function according to parameters is taken

    Quote Originally Posted by Boron View Post
    Unless you make a "typedef enum", both functions will be the same for your compiler.
    Proofed and "no" (leastwise in my case), but don't ask me why, because I'm not an information scientist. The problem was, that sourceModel() referred to a QAbstractItemModel* which hasn't a member with BibtexGlobal::SearchFilter. After an const_cast to my model all worked as expected. Even without a typedef the correct function is called.

    Thanks anyway

    Lykurg

  4. #4
    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: Wrong function according to parameters is taken

    I wouldn't expect it to always work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Wrong function according to parameters is taken

    Quote Originally Posted by wysota View Post
    I wouldn't expect it to always work.
    Depends on compiler/compiler version/plattform?

    Currently I have changed the return value to a QString. Now - barring the original case - it should always work because the function has an other signature?

    Thanks

  6. #6
    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: Wrong function according to parameters is taken

    Quote Originally Posted by Lykurg View Post
    Depends on compiler/compiler version/plattform?
    Yeah, could be. I had a problem once when I had two variants of a method - one taking an int and one taking a string and when I was passing it const char *, it was always picking the int version because the conversion was "closer".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.