How do I save a QByteArray in my Qt panel?
I am creating a RViz plug-in / Qt panel like in this tutorial.
There is a QTableWidget
in this panel and I would like to be able to save/restore the geometry when the user closes/launches again the panel/application.
My save callback looks like this:
void DisplayTopics::save(rviz::Config config) const
{
rviz::Panel::save(config);
QByteArray table_header_state(table_->horizontalHeader()->saveState());
// FIXME Saves an empty string, bug in RViz?
config.mapSetValue("table_header_state", table_header_state);
}
The load callback looks like:
void DisplayTopics::load(const rviz::Config& config)
{
rviz::Panel::load(config);
QVariant table_header_state_var;
if (config.mapGetValue("table_header_state", &table_header_state_var))
{
if (table_header_state_var.canConvert(QMetaType::QByteArray))
{
QByteArray table_header_state(table_header_state_var.toByteArray());
if (!table_header_state.isEmpty())
table_->horizontalHeader()->restoreState(table_header_state);
}
}
}
When the config file is saved, the table_header_state
field is empty:
- Class: topics_rviz_plugin/DisplayTopics
Name: DisplayTopics
table_header_state: ""
I have tested with qDebug
and the QByteArray
is not empty when saving.
Why is the field empty? Full code example is available here: https://gitlab.com/InstitutMaupertuis...
Not an answer, but I seem to remember RViz does something similar. Perhaps VisualizationFrame::saveWindowGeometry(..) can provide some info / inspiration.