QT debug widget cannot call public function - qt

In a QT project, I have a QTableWidget.
I want to look at the QTableWidgetItem in this table in the debugger.
But when I click on the > for the table, it shows nothing.
I have tried to add an Expression Evaluator, like
aTable->item(0,0) but it return < no such value>
Could you tell me what's wrong ? how can I access the objects in a widget ?
thanks

Related

Why show popup function of combobox is not working in qt?

I am new to qt and just experimenting with some functions of comboBox.
I have written the following code
ui->comboBox->addItem("mark");
ui->comboBox->count();
ui->showPopup();
in main window() of project
this code has added mark to the comboBox if i write the following code
ui->comboBox->addItem("mark");
but count() and showPopup() are not working and following error is coming.
class Ui::MainWindow has no member named show Popup.
as you can see in the qt doc here https://doc.qt.io/qt-5/qcombobox.html#showPopup
showPopup is a method defined in the combobox and not in the mainWindows class
so you need to do
ui->comboBox->showPopup();
instead of:
ui->showPopup();
on the other hand, the function count() defined here https://doc.qt.io/qt-5/qcombobox.html#count-prop
is actually returning the number of items in the combobox
so when you do
ui->comboBox->count();
and ignore the returned value, well.. it just get lost in the app...
try comething like
qDebug() << "Elements in CB: " << ui->comboBox->count();
so you can printed in the terminal as a debug message...

Cannot save the contents of a QGraphicsScene in QGraphicsView

I want my application to save the contents of my scene which contains graphics items in it and later be able to retrieve all those items(not as a QPixmap, but as actual individual items).
I have tried using Qsettings but get a QVariant error.
My code is:
QSettings settings("AdvProgLab","ERapp");
settings.beginGroup("MainWindow");
settings.setValue("saved_scene",scene); //Here, scene is a QGraphicsScene
settings.endGroup();
And the error which I am getting is:
qvariant.h:471: error: ‘QVariant::QVariant(void*)’ is private
inline QVariant(void *) Q_DECL_EQ_DELETE;
^
error: use of deleted function ‘QVariant::QVariant(void*)’
Can anybody please explain me where I am going wrong ?
Or is there any other way by which I can achieve this .
Thank You.

QT: How to show combo boxes as cells in a tree view

In a designer-based QT GUI application I'm using a QTreeView to show a tree of elements that is provided by an instance of QStandardItemModel.
The tree-view is multi-column and all elements in the first column are checkable. The screenshot shows an example of how this currently looks like:
Now let's say I'd like the user to be able to select different names for "point". The idea is to have a QComboBox right next to each of the checkboxes. And as alternatives to "point" he may chose from a set of strings, e.g. "point", "pt" and "coord2D". Later on I'd like all selections for all duplicates of "point" to be synchronized but let's start simple...
I'm not too familiar with the idea but to me it looks like the way to go is to create an ItemDelegate for the view as described in the QT Documentation or in this topic (both links refer to QTableWidgets instead of QTreeViews).
So what I did as a first step is I took the example delegate ComboBoxDelegate from the stack overflow question mentioned above and called it from within my application using this code also taken from a related question:
QStandardItemModel* model = new QStandardItemModel(20,2);
ui.tvStructures->setModel(model);
ui.tvStructures->setItemDelegate(new ComboBoxDelegate());
for (int row = 0 ; row < 20; ++row)
{
for (int col = 0; col < 2; ++col)
{
QModelIndex index = model->index(row, col, QModelIndex());
model->setData(index, QVariant((row+1) * (col+1)));
}
}
Note that I placed this code inside the constructor of the parent QDialog where the control element is located. What I ended up is a 2-column table as expected but without any combo boxes. In fact when debugging the code I observe that the constructor of the delegate is called (during the new operation) but none of createEditor, setEditorData, setModelData or updateEditorGeometry every get called. I thought this may be due to the fact that some connection magic is overwriting triggers required to do the drawing but even if I remove all code that refers to the tvStructures QTreeView apart from what I have posted I still can't see any combo boxes.
What's missing?
Note that I'm using the somewhat outdated QT 4.7.1
Looks like you're missing a parent for new QComboBoxDelegate. You can use the QDialog you mentioned as parent.
Also: follow this lengthy example to make sure you're not missing anything else.

Use an QObject found by it's QObjectName

I have a little problem in my program. I have a config file put in settings. I pull from it the names of the object I need to be checked (these are QCheckBox).
I have this piece of code (It compiles and runs but when it's at "cBox->setChecked" it just crash):
void Preproc::on_tBtnManual_toggled(bool checked){
if(checked){
ui->tBtnManual->setText("Systematic");
}else{
ui->tBtnManual->setText("Manual");
settings.beginGroup("Preprocessing");
QStringList keys = settings.childKeys();
foreach(QString configParam,keys){
QCheckBox *cBox = ui->gridLayout->findChild<QCheckBox *>(configParam);
cBox->setChecked(settings.value(configParam).toBool());
}
}
}
I have tried to put ui->cBox->... put it says that cBox is not a child of ui.
If I qDebug(cBox) I have a QObject(0x0) so nothing !
I'm a little new to Qt so maybe it's a simple thing.
Thanks and have a nice day :)
Are you sure that an object is found?
I don't think so (different name? wrong layout?). cBox is 0x0 when nothing is found.
However put a
if (cBox)
before
cBox->setChecked(settings.value(configParam).toBool());
and it will not crash anymore when it doesn't find an object by name.
are you sure the name (content of configParam) is correct?
you can try the search from QApplication
QApplication::instance()->findChild<QCheckBox *>(configParam);
the findChild method performs a recursive search, if the object exists in the hirachie, it will be found. if the object is not found, it could be:
the object does not exist
the object has another name
the object or one of its ancestors has no (NULL) parent
can you post the part of the .ui file with the check box? it would be helpful.

iterate through mdiarea subwindows

I have a mdiArea. I add subwindows to this mdiArea every time an image is opened. The widget I set for each subwindow is imageFileDialog which inherits from the QDialog. Within this dialog I have a spinbox. I want to be able to set the value of this spinbox for every dialog I have in the mdiArea after they have been created. I do not know how to iterate through the dialogs. I tried to think of ways to do this.
for (int j=0; j < ui->mdiArea->subWindowList().size(); j++)
{
imageFileDialog *ifd = ui->mdiArea->subWindowList()[j]->widget();
ifd->setSpinBox(0);
}
but I have an error because I cannot cast the widget as my imageFileDialog class that inherits from QDialog.
I though I might be able to set a connection upon creation of my imageFileDialog:
imageFileDialog *ifd = new imageFileDialog();
ifd->connect(this, SIGNAL(emitImageFileValue(double)), SLOT(ifd->setSpinBox(double)));
subWindow1->setWidget(ifd);
but this is unlike any connection I've tried to make before. Everything compiles fine, but the signal emitted does not reach my slot. I'm hoping someone has tried this before and has some suggestions! Thanks in advance.
Use qobject_cast for the first problem and for the second issue you need to pass only the slot name to the SLOT() macro (without ifd->), or pass the ifd pointer as separate parameter to connect, something like:
QObject::connect(this, SIGNAL(emitImageFileValue(double)), idf, SLOT(setSpinBox(double)));

Resources