Results 1 to 5 of 5

Thread: Problem with virtual functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with virtual functions

    I have changed my code some to make use of pointers, the previous problem is solved but I still have a problem.

    I will try to explain the situation some more.

    I have a treeview which I would like to populate. It is going to be a treeview with a headerbar en below that one level that describes a certain group with its own information and it has child items to have some other information.

    To create this I tried to make one abstract class named AbstractPostItem, this class als functions as the root item of the treeview.

    For the description items in the treeview I created PostHeaderItem which inherits AbstractPostItem and for the child items of PostHeaderItem I created PostDataItem which also inherits AbstractPostItem.

    Now from a dialog I try to create a new PostHeaderItem with its children, for that I use the following code:

    Qt Code:
    1. PostHeaderItem::PostHeaderItem(QStringList files, QString subject, QString group)
    2. {
    3. foreach(QString i, files)
    4. {
    5. PostDataItem *newItem = new PostDataItem(i);
    6. newItem->setSubject(subject);
    7. newItem->setGroup(group);
    8. newItem->setParent(this);
    9. addItem(newItem);
    10. }
    11. setSubject(subject);
    12. setGroup(group);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Which is called from:

    Qt Code:
    1. AbstractPostItem *NewPost::getPost()
    2. {
    3. PostHeaderItem *newItem = new PostHeaderItem(files, ui->inputSubject->text(), ui->inputUsenetGroup->text());
    4. return newItem;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Which is called from:

    Qt Code:
    1. void PostView::newPost()
    2. {
    3. AbstractPostItem *tmpAbstractPostItem;
    4. postScreen = new NewPost(this);
    5. postScreen->setWindowFlags(Qt::Window);
    6. postScreen->setAttribute(Qt::WA_ShowModal);
    7. if(postScreen->exec() == QDialog::Accepted)
    8. {
    9. tmpAbstractPostItem = postScreen->getPost();
    10. postsList->addPost(tmpAbstractPostItem);
    11. postScreen->close();
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Now my problem is that in the first and second code bit everything works just as expected, but when I try to call functions from tmpAbstractPostItem in the third code bit it uses the functions in the AbstractPostItem class instead of the PostHeaderItem class which is what I want.

    So my question is how can I accomplish this?

    Update:
    Added the files as attachment.
    Attached Files Attached Files
    Last edited by eekhoorn12; 7th April 2010 at 23:24.

Similar Threads

  1. QSharedDataPointer and Data with virtual functions
    By niko in forum Qt Programming
    Replies: 0
    Last Post: 2nd February 2010, 08:23
  2. Replies: 3
    Last Post: 17th February 2009, 04:23
  3. Virtual FB problem
    By nrabara in forum Newbie
    Replies: 0
    Last Post: 2nd October 2008, 06:05
  4. problem with virtual function in a .h
    By mickey in forum General Programming
    Replies: 5
    Last Post: 19th April 2008, 18:57
  5. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26

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.