PDA

View Full Version : QTableView->setModel() Qestion



SixDegrees
23rd April 2010, 13:43
We will be using the old-style QFileDialog that permits previewing file contents. We hope to use a QTableView as the preview widget. We will have several plugins that recognize various file types and provide preview information for their specific type. When the user selects a type that has no plugin available, we call tableView->setModel(0), and the QTableView clears itself - exactly the sort of behavior we desire.

Our problem is that this behavior, while sensible, is not documented anywhere, at least that we've noted. In other circumstances, e.g., attempting to call layout->addWidget(0), passing a null pointer to routines will result in a segmentation fault.

We are trying to avoid shooting ourselves in the foot by taking advantage of something that turns out to be a side effect of the current implementation, but which may disappear in future releases. Does anyone know if calling setModel with null is guaranteed to clear the view's display?

squidge
23rd April 2010, 14:30
An alternative (and more future proof) way would be to set the model to a dummy which always returns zero for the number of rows.

SixDegrees
23rd April 2010, 18:45
An alternative (and more future proof) way would be to set the model to a dummy which always returns zero for the number of rows.

Yes, that had occurred to us, also. We were trying to avoid the addition of unecessary classes, but you're correct that this solution is bulletproof.

norobro
23rd April 2010, 19:09
The following should present an empty QTableView:
delete tableView->Model();
Perhaps I misunderstand but if you are worried about future releases this would trouble me more:
This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code

SixDegrees
23rd April 2010, 22:12
The following should present an empty QTableView:
delete tableView->Model();
Perhaps I misunderstand but if you are worried about future releases this would trouble me more:

For better or worse, we don't want to delete the models; as future files are examined, we want to reuse the models to examine file contents.

I'm aware of the risks of using the Qt3 classes. However, Qt4 file dialogs don't offer support for preview widgets, which is a critical need for our application and which Qt3 provided strong support for.

If there's a way to provide a preview widget within a Qt4 file dialog, we would be thrilled to hear about it.

norobro
24th April 2010, 03:44
If there's a way to provide a preview widget within a Qt4 file dialog, we would be thrilled to hear about it.
Well, it shouldn't be too difficult to roll your own.


Create a main QWidget with layout.
Put your QFileDialog and a new QWidget containing your QTableView into the layout.
Connect QFileDialog::currentChanged(QString) to a slot in your preview QWidget.
In the slot open the file, read the data and set the model.

SixDegrees
24th April 2010, 16:18
Well, it shouldn't be too difficult to roll your own.


Create a main QWidget with layout.
Put your QFileDialog and a new QWidget containing your QTableView into the layout.
Connect QFileDialog::currentChanged(QString) to a slot in your preview QWidget.
In the slot open the file, read the data and set the model.


Yes, that's one approach we've considered. The problem is that a QWidget isn't a QDialog; there's quite a bit more involved in order to mimic the behavior of a dialog, such as exec(), accept() and so on. Inheriting from QDialog, and then trying to embed a second QDialog inside, is also problematic.

Perhaps we'll try to grab hold of the QFileDialog QLayout, and figure out some foolproof way of adding another widget to it with proper placement.

I'm surprised this capability has been abandoned. I understand the issues involved with emulating native dialogs, but every system I've seen has provisions for file previews. I hope the ability to do this is restored in a future release.