Results 1 to 6 of 6

Thread: Updating QListView from child dialog

  1. #1
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Updating QListView from child dialog

    Hi All,
    I am new to QT programming and this forum also.
    So please spare any misinterpretations.

    I have a main window application. when launched, the main application calls a function to search system drives, find particular files and update in the list view. works fine.
    i am launching a child dialog from the main window. and a task is to update the main window list view. when i am calling the main window update function to update the list view i am getting a segmentation fault.

    i am pasting the code below...
    please can i get some help on how to do it properly, or what is the error i am doing.


    myapp::myapp(QWidget *parent):QMainWindow(parent),ui(new Ui::myapp)
    {
    ui->setupUi(this);
    ui->listView->setViewMode(QListView::IconMode);
    // setting the model to the current dialog , value declared in header
    model = new QStandardItemModel(this);
    // function to enumerate and update volumes to list
    updateList();
    }

    Void myapp::updateList()
    {
    // function gets specific files from all the local drives and calls
    The updateListView(passing file name as parameter)
    updateListView(filename);
    }

    // function to launch the dialog from main application
    void myapp:nbtnclicked()
    {
    mydialog mdiaog;
    mdialog.setModal(true);
    mdialog.exec();
    }


    // function to insert the value of file into the QFileList
    void myapp:: updateListView (QString file)
    {
    int row = model->rowCount();
    model->insertRows(row,1);

    QStandardItem * item = new QStandardItem(QIcon("C:\\Users\\Test\\Desktop\\med iaa\\red.bmp"),file);

    model->appendRow(item);
    ui->listView->setIconSize(QSize(70,80));
    ui->listView->setModel(model);

    }

    WORKS FINE ON APPLICATION INITIALIZATION

    But when called from a child dialog, i.e. I am calling the updateListView(QString fie) from the child dialog, which is launched by the above main application, segmentation error is caused.

    Code I am using to call the main application function from child dialog is

    bool myDialog::updateGui(QString path)
    {
    ((myapp*)parent())->updateListView (fileName);
    return true;
    }

    Function is called OK, but throws segmentation error in Main Applications, updateListView()

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QListView from child dialog

    You missed to set the parent.
    Qt Code:
    1. void myapp:nbtnclicked()
    2. {
    3. mydialog mdiaog(this); //<<<<<<<<<<
    4. mdialog.setModal(true);
    5. mdialog.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    EDIT: Make sure the parent is being passed on to the QDialog in the mydialog ctor.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Updating QListView from child dialog

    Hello santosh,
    I did not get exactly what to modify ?

    should i declare the parent for the child dialog in the constructor or should i pass the parent while creating the child dialog ??

    any code help would be great.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QListView from child dialog

    Show mydialog ctor
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Updating QListView from child dialog

    mydialog::mydialog(Qwidget *parent) : Qdialog (parent), ui(new Ui::myDialog)
    {
    ui->setupUi(this);

    }

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QListView from child dialog

    Do this modification
    Qt Code:
    1. void myapp:nbtnclicked()
    2. {
    3. mydialog mdiaog(this); //<<<<<<<<<< add "this"
    4. mdialog.setModal(true);
    5. mdialog.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. How to access objects of parent Dialog from Child Dialog .
    By ranjit.kadam in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 07:39
  2. Updating QListView from a thread
    By Paul1892 in forum Newbie
    Replies: 2
    Last Post: 12th July 2010, 14:44
  3. closing child dialog closes parent dialog
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 20:46
  4. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 14:01
  5. QListView not updating
    By Terabyte in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2009, 08:10

Tags for this Thread

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.