Results 1 to 4 of 4

Thread: Two probably simple Qt4 Questions

  1. #1
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    40
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Two probably simple Qt4 Questions

    I have been studying the SDI/MDI example in my Qt4 and in my book Foundations of Qt development. I have two questions. I tried to provide enough details. If I wrote to much I apologize.

    1.

    In the Qt4 example there is a line of code

    Qt Code:
    1. newAct->setShortcuts(QKeySequence::New);
    To copy to clipboard, switch view to plain text mode 

    The line with same functionality in the book is

    Qt Code:
    1. newAction->setShortcut( tr("Ctrl+N") );
    To copy to clipboard, switch view to plain text mode 

    I have read the help provided with the Qt there is a whole table of values for enum QKeySequence::StandardKey. As far as I have managed to conclude the first version
    Qt Code:
    1. QKeySequence::QKeySequence ( StandardKey key )
    To copy to clipboard, switch view to plain text mode 
    is platform dependent. It doesn't say, as far as I can see if second version
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    is platform dependent.

    Is there any real difference between these to versions and if there are some what are they?

    2.

    There was a thread about this but it didn't clarify it for me at all.

    If I have type class B for instance and I want to use it as a member in my type class A. Code that I would use would look something like this.

    class_B.h
    Qt Code:
    1. #ifndef CLASS_B_H
    2. #define CLASS_B_H
    3.  
    4. class B
    5. {
    6. //some code
    7. }
    8.  
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    class_B.cpp
    Qt Code:
    1. #include "class_B.h"
    2. //some code
    To copy to clipboard, switch view to plain text mode 

    class_A.h
    Qt Code:
    1. #ifndef CLASS_A_H
    2. #define CLASS_A_H
    3.  
    4. #include "class_B.h"
    5.  
    6. class A
    7. {
    8. private:
    9. B b;
    10. //some code
    11. }
    12.  
    13. #endif
    To copy to clipboard, switch view to plain text mode 

    In the example in Qt class MainWindow derived from QMainWindow has QAction class member among others. But instead of including the QAction header the code is

    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2. class QAction;
    3. class QMenu;
    4. class QTextEdit;
    5. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 

    Will somebody explain to me what this code do exactly or where can I read it in details. I failed to find it in the Qt help. Why not just include all the headers? I know that namespace for instance can be a problem. When using for instance string from Standard template library even when you include the string header you need to write using std::string or to declare every string object with std:string sBuffer so that compiler can use the right type.

    I would appreciate any help you can provide. Thanks in advance.

  2. #2
    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: Two probably simple Qt4 Questions

    Quote Originally Posted by frenk_castle View Post
    Is there any real difference between these to versions and if there are some what are they?
    Yes there is a difference.
    Qt Code:
    1. newAction->setShortcut( tr("Ctrl+N") );
    To copy to clipboard, switch view to plain text mode 
    is "hard coded" (not really platform dependent) which means that the action is triggered everywhere only by Ctrl+N.

    Qt Code:
    1. newAct->setShortcuts(QKeySequence::New);
    To copy to clipboard, switch view to plain text mode 
    uses a platform depended short cut to which the users is used to. So that is the better choice for programming for multiple targets because the user can use his familiar short cuts.

    But if you only look for windows there is no difference because QKeySequence::New is expanded to Ctrl+N...
    EDIT: and also for all other platforms... (which are known today). But anyway this is only a special case for a new file. other "actions" like MoveToEndOfLine are different on Win and Mac...
    Last edited by Lykurg; 16th September 2009 at 11:55.

  3. #3
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    40
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Two probably simple Qt4 Questions

    Thank you Lykurg. You explained it much better that Qt help. Especially because I plan to write cross-platform code.

    If somebody could answer the second question or direct me where to look/read. I tried to search the net and help but came up empty. I could just copy the code but I hate copying code which I don't know exactly what it does. When error occurs and they always do it is hard to fix it with "borrowed" code.

  4. #4
    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: Two probably simple Qt4 Questions

    for the
    Qt Code:
    1. class XYZ;
    To copy to clipboard, switch view to plain text mode 
    in a header file, look for various sites about "forward declaration". it can save you some compilation time and you should normally prefer this. Right now I don't know how the macros QT_BEGIN_NAMESPACE and QT_END_NAMESPACE are expanded, but you don't need them in your personal code. So just skip that macros.

Similar Threads

  1. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  2. Simple DB app, some questions.
    By juannm in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2008, 11:46
  3. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  4. simple questions. qt3 to qt4
    By impeteperry in forum Newbie
    Replies: 16
    Last Post: 3rd April 2006, 17:41
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.