Results 1 to 6 of 6

Thread: Why QWindow is not initialized with the NEW keyword?

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why QWindow is not initialized with the NEW keyword?

    To create a window we can do:

    QWidget window;

    Can we also do:

    QWidget window = new QWindow;


    How can we create a window without the NEW keyword? What type of class is it?

  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: Why QWindow is not initialized with the NEW keyword?

    Quote Originally Posted by probine View Post
    How can we create a window without the NEW keyword?
    Ahh... you can create one if you read a introduction into C++!!! Come on, that is so basic stuff!
    Qt Code:
    1. QWidget* window = new QWidget();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why QWindow is not initialized with the NEW keyword?

    Quote Originally Posted by probine View Post
    To create a window we can do:

    QWidget window;

    Can we also do:
    This:
    QWidget window = new QWindow;
    is wrong. With new keyword you have to use a pointer type:
    Qt Code:
    1. QWidget *window = new QWidget;
    To copy to clipboard, switch view to plain text mode 

    How can we create a window without the NEW keyword?
    Normally, like any other objects.
    What type of class is it?
    hmm it depends what type of object you make:
    Qt Code:
    1. int a; // this is int
    2. QWidget w; // this is QWidget
    3. QListView lv; //this is QListView
    To copy to clipboard, switch view to plain text mode 

    Generally, widgets should be created on a heap (so with new keyword) but in main() function it is good to create main widget on stack so it will be deleted when going out of scope which is when your application exit.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QWindow is not initialized with the NEW keyword?

    Thanks for the answers. And even though it seems basic, the question is much more complex. Pretend:
    _____
    class Person
    {
    ...
    // Anything that a class will have goes here
    }
    _____

    To instantiate this class I must do:

    Person myPerson = new Person();


    I couldn't do:

    Person myPerson;


    Base on this example does it mean that QWidget is a regular class, a struct or what?

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why QWindow is not initialized with the NEW keyword?

    Quote Originally Posted by probine View Post
    Thanks for the answers. And even though it seems basic, the question is much more complex. Pretend:
    _____
    class Person
    {
    ...
    // Anything that a class will have goes here
    }
    _____

    To instantiate this class I must do:

    Person myPerson = new Person();


    I couldn't do:

    Person myPerson;


    Base on this example does it mean that QWidget is a regular class, a struct or what?
    Your code will only work in case it is a Java code. Are coding in Java or C++?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    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: Why QWindow is not initialized with the NEW keyword?

    Quote Originally Posted by probine View Post
    To instantiate this class I must do:

    Person myPerson = new Person();
    This will only compile with MS Visual C compiler. But this is syntactically incorrect as far as C++ standard is concerned.
    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. why MACROS are used between class name and class keyword
    By babu198649 in forum General Programming
    Replies: 6
    Last Post: 4th February 2009, 13:30
  2. "emit" keyword optional when calling signals?
    By will49 in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2008, 01:13
  3. variable in method not initialized?!
    By frosch in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2006, 14:09
  4. Parenting QWindow...
    By roomie in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 09:06
  5. Replies: 2
    Last Post: 29th May 2006, 10:46

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.