Results 1 to 6 of 6

Thread: no matching function for call to object map(*it);

  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default no matching function for call to object map(*it);

    I am trying to make call to a function multiple times but parallelly using QtConcurrent::mapped

    But I am not able to over come below error.

    error: no matching function for call to object of type 'addWrapper' *result = map(*it); ^~~ The code is as follows

    Qt Code:
    1. struct addWrapper {
    2. loadbook *instance;
    3. typedef QString result_type;
    4. addWrapper(loadbook *lBook) : instance(lBook) {}
    5. QString operator()(QString &item) {
    6. instance->decrypt->decryptFile(item,'A');
    7.  
    8. }
    9. };
    10.  
    11. addWrapper wrapper(this);
    12.  
    13. QFuture<QString> returnContent = QtConcurrent::mapped(fileList,wrapper);
    To copy to clipboard, switch view to plain text mode 
    kindly help me resolve this issue.

  2. #2
    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: no matching function for call to object map(*it);

    Why are you complicating things so much?

    Qt Code:
    1. #include <QtConcurrentMap>
    2. #include <QStringList>
    3. #include <QByteArray>
    4. #include <QFile>
    5.  
    6. struct Decrypter {
    7. Decrypter(const QByteArray &key) : m_key(key) {}
    8.  
    9. typedef QByteArray result_type;
    10.  
    11. QByteArray operator()(const QString &fileName) {
    12. QFile f(fileName);
    13. if(!f.open(QIODevice::ReadOnly)) return QByteArray();
    14. QByteArray result;
    15. result.reserve(f.size());
    16. int keyIndex = 0;
    17. char input;
    18. char keyByte;
    19. while(!f.atEnd()) {
    20. f.getChar(&input);
    21. keyByte = m_key.at(keyIndex);
    22. keyIndex = (keyIndex+1) % m_key.size();
    23. result.append( input ^ keyByte );
    24. }
    25. return result;
    26. }
    27. private:
    28. QByteArray m_key;
    29. };
    30.  
    31. int main() {
    32. QStringList filesToDecrypt = { "file1", "file2", "file3" };
    33. QFuture<QByteArray> future = QtConcurrent::mapped(filesToDecrypt, Decrypter("abcdef"));
    34. return 0;
    35. }
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: no matching function for call to object map(*it);

    I think you have a mismatch in your function signature.
    Try a const reference for the operator argument.

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    ejoshva (11th March 2015)

  5. #4
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: no matching function for call to object map(*it);

    Thank you wysota and anda_skoa for you help.

    @Wysota, I have made my decryt() re-entrant.
    Qt Code:
    1. QString Decrypt::decryptFile(QString sourceFile)
    2. {
    3. QString decryptedContent;
    4. decryptedContent.clear();
    5. string srcFile=sourceFile.toUtf8().constData();
    6. ifstream ffin;
    7.  
    8. ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
    9. QChar keystring = 'A';
    10. char keyToEncryption= keystring.toLatin1();
    11. if(ffin.is_open())
    12. {
    13. char ch;
    14. while(!(ffin.read(&ch,1).eof()))
    15. {
    16. ch ^= keyToEncryption;
    17. decryptedContent.append(ch);
    18. }
    19. }
    20. ffin.close();
    21. return decryptedContent;
    22.  
    23. }
    24.  
    25. QString Decrypt::decryptFile(QString sourceFile,QChar keystring)
    26. {
    27. _decrptedResStr.clear();
    28. string srcFile=sourceFile.toUtf8().constData();
    29. ifstream ffin;
    30.  
    31. ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
    32.  
    33. char keyToEncryption= keystring.toLatin1();
    34. if(ffin.is_open())
    35. {
    36. char ch;
    37. while(!(ffin.read(&ch,1).eof()))
    38. {
    39. ch ^= keyToEncryption;
    40. _decrptedResStr.append(ch);
    41. }
    42. }
    43. ffin.close();
    44. return _decrptedResStr;
    45. }
    To copy to clipboard, switch view to plain text mode 

    I didn't realise what you were telling. Only upon pondering what's wrong got the issue. Now have modified to the first function above. Earlier it was of type 2nd function.

    Thank you so much


    Added after 16 minutes:


    @anda_skoa : Thank you so much. You have pointed out exactly. It works now.

    Qt Code:
    1. QFuture<QString> decryptedContent = QtConcurrent::mapped(fileList,DecryptMap('A'));
    2.  
    3. struct DecryptMap {
    4. DecryptMap(const QChar &key) : m_key(key) {}
    5. typedef QString result_type;
    6.  
    7. QString operator()(const QString &item)
    8. {
    9. Decrypt *decrypt = new Decrypt();
    10. return decrypt->decryptFile(item,'A');
    11. }
    12. QChar m_key;
    13. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by ejoshva; 11th March 2015 at 04:06.

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: no matching function for call to object map(*it);

    Quote Originally Posted by ejoshva View Post
    Qt Code:
    1. QString operator()(const QString &item)
    2. {
    3. Decrypt *decrypt = new Decrypt();
    4. return decrypt->decryptFile(item,'A');
    5. }
    6. };
    To copy to clipboard, switch view to plain text mode 
    You are leaking the Decrypt instance, i.e. there is a "new" but no "delete".
    Better create it on the stack, i.e. without new, then it is destroyed when the operator's scope ends.

    Cheers,
    _

  7. #6
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: no matching function for call to object map(*it);

    @anda_skoa : thanks for pointing it out. will take care now

Similar Threads

  1. Replies: 5
    Last Post: 5th December 2013, 04:37
  2. Replies: 7
    Last Post: 23rd September 2012, 16:53
  3. about no matching function for call to
    By Alain Delon in forum General Programming
    Replies: 1
    Last Post: 5th March 2011, 21:30
  4. no matching function for call to setupUi
    By ctote in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2010, 15:20
  5. No Matching function to call...
    By weepdoo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2008, 17:30

Tags for this Thread

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.