Results 1 to 18 of 18

Thread: A couple of newbie QT questions

  1. #1

    Default A couple of newbie QT questions

    Hi, I was looking at QT as a cross-platform language to use and I had a couple questions/concerns I couldn't find answers to online.

    1. I heard from a friend's friend (info is a bit sketch) that we couldn't inherit or override anything. This seems false as from what I've seen you can inherit and create custom widgets. So are there restrictions on inheriting/overriding at all? Are there specific classes/widgets that we're not allowed to extend?

    2. I'd like to know if there are a lot of debugging issues involved with multiple platform deployment (sorta like Java's write once debug everywhere..). I haven't found any posts really relating to this issue or going in depth, so I'd like to hear from those who've actually deployed to multiple platforms (actually just OSX/Linux - I'm planning to develop in Windows).


    Thanks in advance!

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    Qt isn't a cross-platform language. It's a cross-platform framework. Underneath it's all C++, so of course you can inherit and override things as you wish, in fact, this is how a lot of the functionality is obtained. You take a standard component (say, a QTextEdit), modify it to suit by creating your own class, inheriting QTextEdit, and overriding various methods.

    Debugging is the same - if you can debug your C++ code already, you can debug your Qt framework code. The only added extra is a "Debugging helper" that gives more meaningful information about some of the classes such as QString.

  3. #3

    Default Re: A couple of newbie QT questions

    Bad use of language; I know it's all C++ under. It's just that I'm was concerned about what I heard and wasn't sure if there were any classes that Trolltech made un-inheritable or if they simply disallow inheritance for specific classes. Good to know that's not the case.

    As for debugging, mostly I mean like it works on Windows XP say, but then some weird behaviour pops up as I run it on Ubuntu or OSX. Happens on Java, but that might be because I have to compile it on different platforms itself and their compiler's aren't exactly the same.

  4. #4
    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: A couple of newbie QT questions

    Quote Originally Posted by fishing_boat View Post
    1. I heard from a friend's friend (info is a bit sketch) that we couldn't inherit or override anything. This seems false as from what I've seen you can inherit and create custom widgets. So are there restrictions on inheriting/overriding at all? Are there specific classes/widgets that we're not allowed to extend?
    Inheritance works, it's just C++. There are some restrictions in the case of multiple inheritance where ancestor classes are derived from QObject. Only one ancestor can be derived from QObject, and it must be listed first in the class definition. I've never run foul of this restriction... perhaps others here have?

  5. #5

    Default Re: A couple of newbie QT questions

    I'm a bit muddy on LGPL. I know that I can release my software close-source, and need to link dynamically and that if I change anything in QT itself I need to release that.

    However this is a bit confusing to me:

    "The LGPL contains no special provisions for inheritance, because none are needed. Inheritance creates derivative works in the same way as traditional linking, and the LGPL permits this type of derivative work in the same way as it permits ordinary function calls"

    It says it's similar to traditional linking (statically right?) which I can't do if I want my code to be close-sourced; then it says it permits this like ordinary function calls which implies that we can use it without open-sourcing.

    So if I do extend a QT object but I don't add it to the QT library (ie it's part of my code), do I need to open-source?

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    No, as your not modifying the Qt source code. Secondly, if you read the Nokia exception license (not the LGPL license) you get the additional rights of being able include material from header files, and so derive from that material. You also get other rights which you probably don't care about at the moment, but sometimes will be useful.

  7. #7
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: A couple of newbie QT questions

    One more thing about inheritance: In Java, you cannot override a method that was marked as "final". So the default is that you can override a method. In C++, it is the other way around: To mark a method as overwriteable you have to mark it as "virtual". You can only override the methods from Qt that nokia marked virtual. Sometimes people argue that there is not enough virtual methods in Qt but I have not seen any limitations here. It is just another theory how people come to conclusions like your fellow there.
    It's nice to be important but it's more important to be nice.

  8. #8

    Default Re: A couple of newbie QT questions

    I know it's bad, but are we forbidden by Nokia from redefining an inherited non-virtual function? (I'm not going to do it, just curious)

  9. #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: A couple of newbie QT questions

    No, Nokia doesn't forbid you from redefining non-virtual functions. But your C++ knowledge should tell you it doesn't make much sense to reimplement non-virtual methods.
    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.


  10. #10
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: A couple of newbie QT questions

    You are not forbidden to do that. C++ usually allows you to shot yourself in the foot. It just will not work as expected so you should only do it if you know what you are doing.

    Is there any conrete example where you would need that? If you need it, you very likely try to use the API in a wrong way.
    It's nice to be important but it's more important to be nice.

  11. #11
    Join Date
    Aug 2006
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    I got an example where simple inheritance constraint is a pain.
    I m working on a Network module.

    I want to design a client and and server class.
    The first could derive from QTcpSocket and the second from QTcpServer but I'd like those two classes to share base attributes and methods.

    are mysimple class definitions

    Qt Code:
    1. class someclass ;
    2. class base
    3. {
    4. public:
    5. base ():someattribute(){}
    6. ~ base(){}
    7. someclass someattribute;
    8. };
    9. class client : public QTcpSocket, public base
    10. {
    11. Q_OBJECT
    12. public:
    13. client (QOject *o):QTcpSocket(o),base(){}
    14. ~ client (){}
    15.  
    16. };
    17. class server : public QTcpServer, public base
    18. {
    19. Q_OBJECT
    20. public:
    21. server (QOject *o): QTcpServer(o),base(){}
    22. ~ server (){}
    23. };
    To copy to clipboard, switch view to plain text mode 

    while this C++ quite acceptable moc compiler get stuck and require base class to be an QObject.
    If the base class becomes a QOject such as

    Qt Code:
    1. class base : public virtual QOject
    2. {
    3. Q_OBJECT
    4. public:
    5. base (QOject *o):QOject(o),someattribute(){}
    6. ~ base(){}
    7. someclass someattribute;
    8. };
    To copy to clipboard, switch view to plain text mode 
    there are ambiguities @ compilation time that the compiler can't resolve.

  12. #12

    Default Re: A couple of newbie QT questions

    Nonono. For sure I'm not going to be doing that; just curious about what Nokia does or does not enforce.

    Thanks for the feedback.

  13. #13
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: A couple of newbie QT questions

    You would usually not inherit the sockets but have a class and the sockets as member.
    It's nice to be important but it's more important to be nice.

  14. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    Quote Originally Posted by fishing_boat View Post
    I know it's bad, but are we forbidden by Nokia from redefining an inherited non-virtual function? (I'm not going to do it, just curious)
    Think about it for a minute. If you have a base class BC and you inherit from it and call it IC, and then override non-virtual function F. What will happen?

    BC *base = new IC();
    IC *iclass = new IC();

    base->F(); // Calls the original function
    iclass->F(); // Calls your overridden function

    Now, if we make F virtual, F() will always call your overridden function regardless. Therefore it doesn't make sense to override a function that isn't virtual, unless you are only ever going to call it through your inherited class type, rather than the base class type. Even then, it just means confusion, as you could have some code calling the Qt function, and some calling your function. Lots of fun with the debugger will begin.

    Nokia will not hunt you down for doing the above.

  15. #15

    Default Re: A couple of newbie QT questions

    I know how virtual/non-virtual works in C++... just curious about what Nokia allows.

  16. #16
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    They'll come down on you hard if you put there code in your own software and make it closed source without a commercial license, unless that code has been excluded by the Nokia exception license included with Qt. It's really that simple. Including headers for the purpose of using and inheriting from Qt objects is one such exemption.

    Have you read the Nokia exception license?

  17. #17

    Default Re: A couple of newbie QT questions

    I've read the licensing information at http://qt.nokia.com/products/licensing and the LGPL (tried to at least, some of that licencing stuff is confusing). I don't think that's what you're talking about though, are you talking about the bottom of "http://qt.nokia.com/doc/4.6/lgpl.html"?

    I don't think I'll be statically linking anything or copy+pasting their code into mine if that's what you mean. by "put their code in your own software".

  18. #18
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A couple of newbie QT questions

    The Nokia exception license is different depending on if you use 4.5 (where its V1.0) or 4.6 (V1.1).

    The 1.0 version for QT4.5 and earlier goes like this:
    Nokia Qt LGPL Exception version 1.0

    As a special exception to the GNU Lesser General Public License
    version 2.1, the object code form of a "work that uses the Library"
    may incorporate material from a header file that is part of the
    Library. You may distribute such object code under terms of your
    choice, provided that the incorporated material (i) does not exceed
    more than 5% of the total size of the Library; and (ii) is limited to
    numerical parameters, data structure layouts, accessors, macros,
    inline functions and templates.
    Whereas the V1.1 version for Qt 4.6 is:


    Nokia Qt LGPL Exception version 1.1

    As an additional permission to the GNU Lesser General Public License version
    2.1, the object code form of a "work that uses the Library" may incorporate
    material from a header file that is part of the Library. You may distribute
    such object code under terms of your choice, provided that:
    (i) the header files of the Library have not been modified; and
    (ii) the incorporated material is limited to numerical parameters, data
    structure layouts, accessors, macros, inline functions and
    templates; and
    (iii) you comply with the terms of Section 6 of the GNU Lesser General
    Public License version 2.1.

    Moreover, you may apply this exception to a modified version of the Library,
    provided that such modification does not involve copying material from the
    Library into the modified Library's header files unless such material is
    limited to (i) numerical parameters; (ii) data structure layouts;
    (iii) accessors; and (iv) small macros, templates and inline functions of
    five lines or less in length.

    Furthermore, you are not required to apply this additional permission to a
    modified version of the Library.
    Both can be found in the LGPL_EXCEPTION file in the same directory as the other license documents.

Similar Threads

  1. Replies: 0
    Last Post: 10th October 2009, 05:44
  2. Replies: 10
    Last Post: 5th August 2009, 11:53
  3. Newbie Questions
    By Pether in forum Newbie
    Replies: 9
    Last Post: 15th July 2009, 08:32
  4. A couple of questions on installing Qt 4.5 on Windows Xp
    By rishiraj in forum Installation and Deployment
    Replies: 2
    Last Post: 3rd April 2009, 07:44
  5. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03

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.