Results 1 to 19 of 19

Thread: Type conversion on container templates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Question Type conversion on container templates

    Actually i did alot changing on code and googling, if it's make you feel better, i suffering myself to don't ask a question!
    But i have to do :|


    I have c++ class with a this function
    Qt Code:
    1. std::string addUri(std::vector<std::string> uris, std::map<std::string, std::string> options);
    To copy to clipboard, switch view to plain text mode 
    All i want to do is make a qt wrap function for it
    Like:
    Qt Code:
    1. QString addUri(QVector<QString> uris, QMap<QString, QString> options);
    To copy to clipboard, switch view to plain text mode 

    The wrap one isn't right
    I will apperciate to help me in this conversion
    tahnks
    Last edited by Alir3z4; 27th January 2012 at 23:45. Reason: updated contents
    ...یه مرد هیچوقت زمین نمیخوره

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Type conversion on container templates

    What's "not right" about it?

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Type conversion on container templates

    passing std::vector<std::string> uris, std::map<std::string, std::string> options by value is a lot wwrse than passing most Qt types by value. You should be passing stl containers by const ref, not value.

    If you conversion from stl to Qt is not correct, then you should show us your attempt at that code.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Type conversion on container templates

    Here you can see the source code, it's on the git
    yoDownet/yoDownloaders/aria2c.h
    aria2c.h is a c++ source, which i wan't to make a qt function wraper for it.
    there is a qt/class called Downloader which my program access to aria2c.h throght it.
    i don't know how to implement such function to handle type conversion.
    Qt Code:
    1. QString addUri(QVector<QString> uris, QMap<QString, QString> options);
    To copy to clipboard, switch view to plain text mode 
    i hope i explained my point as well

    ##update:
    i think i didn't push the local git repo to remote, that's why the Downloader class isn't available on the git :|
    Last edited by Alir3z4; 28th January 2012 at 14:08. Reason: updated contents
    ...یه مرد هیچوقت زمین نمیخوره

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Type conversion on container templates

    There are several steps:
    How do you convert QString to std::string?
    How do you convert QVector to std::vector?
    How do you convert QMap<QString, QString> to std::map<std::string, std::string>?

    QString qs("abc");
    std::string x(qs.toStdString());

    QVector<QString> = qsv;
    qsv.push_back(qs);

    std::vector<std::string> sv;
    sv.push_back(qs.toStdString());

    or

    sv.resize(qsv.size());
    sv[some_index] = qsv[some_index].toStdString();

    etc.

    if you feel adventurous, you can do it in very few lines with std::transform and a suitable functor
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. The following user says thank you to amleto for this useful post:

    Alir3z4 (29th January 2012)

  7. #6
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Exclamation Re: Type conversion on container templates

    The actual thing i wanna do is making conversion at the template argument, not getting them one by one!
    like:
    Qt Code:
    1. const QString addUri(const QVector< const std::string(QString::toStdString()) > uris);
    To copy to clipboard, switch view to plain text mode 
    huh? what are you talking about dah?
    but all i've got every time is delicious error :|
    Last edited by Alir3z4; 29th January 2012 at 17:59. Reason: updated contents
    ...یه مرد هیچوقت زمین نمیخوره

  8. #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: Type conversion on container templates

    I'm sorry, what exactly is the problem? You have problems with function signature or with function body? What is the error you are getting?
    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.


  9. #8
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Exclamation Re: Type conversion on container templates

    Quote Originally Posted by wysota View Post
    I'm sorry, what exactly is the problem? You have problems with function signature or with function body? What is the error you are getting?
    i didn't even implement the function body
    this is the error!

    Qt Code:
    1. make: Entering directory `/home/alireza/dev/qt/yoDownet-build-desktop-Qt_in_PATH_Debug'
    2. g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I../yoDownet -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtSql -I/usr/include -I. -I. -I../yoDownet -I. -o downloader.o ../yoDownet/downloader.cpp
    3. In file included from ../yoDownet/downloader.cpp:1:0:
    4. ../yoDownet/downloader.h:17:77: error: template argument 1 is invalid
    5. make: Leaving directory `/home/alireza/dev/qt/yoDownet-build-desktop-Qt_in_PATH_Debug'
    6. make: *** [downloader.o] Error 1
    7. 22:36:00: The process "/usr/bin/make" exited with code 2.
    8. Error while building project yoDownet (target: Desktop)
    9. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    Don't tell me give us the source code, coz the whole header file goes to 5 lines :|
    Last edited by Alir3z4; 29th January 2012 at 18:33. Reason: updated contents
    ...یه مرد هیچوقت زمین نمیخوره

  10. #9
    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: Type conversion on container templates

    And the exact line triggering the error (downloader.h:17 and :77)?
    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. Replies: 4
    Last Post: 3rd January 2011, 22:00
  2. conversion between string to hex and vice versa
    By mohanakrishnan in forum Newbie
    Replies: 2
    Last Post: 5th December 2009, 11:25
  3. int to String Conversion
    By aj2903 in forum Qt Programming
    Replies: 4
    Last Post: 4th December 2009, 22:43
  4. Conversion Char Array to string
    By anafor2004 in forum Newbie
    Replies: 6
    Last Post: 6th May 2008, 14:35
  5. template parameter and conversion operator
    By bitChanger in forum General Programming
    Replies: 7
    Last Post: 21st April 2006, 15:36

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.