Results 1 to 3 of 3

Thread: Proper way of testing whether Qt is being used by a program

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Proper way of testing whether Qt is being used by a program

    I have a small library which I would like to be used with both Qt and non-Qt programs. Basically I want to use QList if the calling program will be using Qt anyway, else I want to use std::list. So I am thinking of using #define-s like:

    Qt Code:
    1. #ifdef QT_VERSION
    2. #define MYLIST QList
    3. #else
    4. #include <list>
    5. #define MYLIST std::list
    6. #endif
    To copy to clipboard, switch view to plain text mode 

    ... and then use MYLIST throughout my code. I think it is safe to assume for practical purposes that if QT_VERSION is defined, Qt is being used? Is this OK? I want to know what is the accepted/conventional of testing whether Qt is being used.

    In relation, if a program uses Qt, does it mean it also uses std::list anyway? I'm asking since QList seems to have facilities to convert to and from std::list which may not be possible if std::list is not used somewhere inside Qt?
    Last edited by jamadagni; 10th August 2012 at 07:49. Reason: missing [code] tags
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  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: Proper way of testing whether Qt is being used by a program

    QList is not a wrapper around std::list, QString is not a glorified std::string wrapper etc. Qt applications can be built with some support for conversion to/from STL types. However, if Qt is compiled with the "-no-stl" configure option then the Qt to STL functions will not be present. At compile time this is seen as a defined QT_NO_STL.

    Even with STL support, the Qt containers are not 100% interchangeable with their STL counterparts: no reverse STL-style iterator on a QList for example. Just substituting QList for std::list may not work.

  3. #3
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Proper way of testing whether Qt is being used by a program

    Hello and thanks for reminding me of the difference in API between QList and std::list etc. I am perfectly aware of it though. Obviously I'd only be using whatever is common between the two.

    If you have an answer to my actual question I'd appreciate that. Thanks.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

Similar Threads

  1. Testing Qt-Software with a GUI Testing Tool
    By nightghost in forum Qt Programming
    Replies: 8
    Last Post: 22nd February 2012, 07:43
  2. Proper way to use qmake and moc?
    By mossen in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 02:52
  3. Replies: 2
    Last Post: 9th December 2010, 14:11
  4. Replies: 5
    Last Post: 29th October 2007, 22:49
  5. Proper way to #include Qt?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 02:15

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
  •  
Qt is a trademark of The Qt Company.