Edit variables from other widget of QStackedWidget
-
@hobbyProgrammer said in Edit variables from other widget of QStackedWidget:
But won't that instantly trigger the showResult?
No, why should it? connect() does not call anything. It just connects the signal to the slot. You have to emit the signal in order the slot being called. This is how signal/slot works.
-
@jsulm on my advanced construction it doesn't seem to work.
I have a mainWindow and a QWidget. The widget contains a promoted QGraphicsView. I'd like to retreive information from the QGraphicsView to the mainWindow.
I already tried by emitting a signal in QGraphicsView and connect it in the QWidget to a slot that sets a public integer to that value and send a signal for MainWindow. Then I go to the mainWindow and connect the signal from QWidget to a slot that handles the rest.It doesn't go to the signal in the QWidget.
this is the code in the QWidget:
#include "overview.h" #include "ui_overview.h" Overview::Overview(QWidget *parent) : QWidget(parent), ui(new Ui::Overview) { ui->setupUi(this); overviewView *ovView = qobject_cast<overviewView*>(ui->graphicsView); connect(ovView, &overviewView::valAdded, this, &Overview::giveSignalToMainWindow); } Overview::~Overview() { delete ui; } void Overview::giveSignalToMainWindow() { qDebug() << "overview"; emit editFinished(); val = ui->graphicsView->value; qDebug() << "Overview ui->graphicsView->value: "<< ui->graphicsView->value; }
-
@hobbyProgrammer I'm not sure I understand: do you mean slot connected to editFinished() is not called?
-
void overviewView::loadFromCSV() { QString fileName = "C://users//user1//downloads//data.csv"; QFile csvFile(fileName); QStringList dataList; if(csvFile.open(QIODevice::ReadOnly)) { QString data; data = csvFile.readAll(); dataList = data.split('\n'); csvFile.close(); } for(int i = 0; i < dataList.size(); i++) { QString data2 = dataList.at(i); QStringList dataList = data2.split(","); for(int j = 0; j < dataList.size(); j++) { val = dataList.at(j); } } emit valAdded(); qDebug() << "overviewview: " << val; }
-
@hobbyProgrammer You made sure overviewView::valAdded was called?
Do you really have only one overviewView instance (I'm asking because this is a mistake people often do :-))?Is ovView not nullptr here:
overviewView *ovView = qobject_cast<overviewView*>(ui->graphicsView);
?
-
@hobbyProgrammer Check what connect() returns.
-
@hobbyProgrammer Do you actually have event loop running when you emit the signal?