Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Edit variables from other widget of QStackedWidget
Forum Updated to NodeBB v4.3 + New Features

Edit variables from other widget of QStackedWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qwidgetqstackedwidget
14 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H hobbyProgrammer

    @jsulm alright, thank you. But won't that instantly trigger the showResult?
    I would like to show the result only when someone chooses it in the menubar.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @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.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    H 2 Replies Last reply
    0
    • jsulmJ jsulm

      @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.

      H Offline
      H Offline
      hobbyProgrammer
      wrote on last edited by
      #5

      @jsulm Thank you! It works.

      1 Reply Last reply
      0
      • jsulmJ jsulm

        @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.

        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #6

        @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;
        }
        
        jsulmJ 1 Reply Last reply
        0
        • H hobbyProgrammer

          @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;
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @hobbyProgrammer I'm not sure I understand: do you mean slot connected to editFinished() is not called?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          H 1 Reply Last reply
          0
          • jsulmJ jsulm

            @hobbyProgrammer I'm not sure I understand: do you mean slot connected to editFinished() is not called?

            H Offline
            H Offline
            hobbyProgrammer
            wrote on last edited by
            #8

            @jsulm No I mean that Overview::giveSignalToMainWindow is not even called.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hobbyProgrammer
              wrote on last edited by
              #9
              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;
              }
              
              jsulmJ 1 Reply Last reply
              0
              • H hobbyProgrammer
                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;
                }
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @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);
                

                ?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @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);
                  

                  ?

                  H Offline
                  H Offline
                  hobbyProgrammer
                  wrote on last edited by
                  #11

                  @jsulm I added qDebug() << ovView
                  and it gave me this:

                  overviewView(0x1fef8160, name="graphicsView")
                  

                  so it doesn't seem to be a nullptr.
                  Also I have only 1 ovView.

                  jsulmJ 1 Reply Last reply
                  0
                  • H hobbyProgrammer

                    @jsulm I added qDebug() << ovView
                    and it gave me this:

                    overviewView(0x1fef8160, name="graphicsView")
                    

                    so it doesn't seem to be a nullptr.
                    Also I have only 1 ovView.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @hobbyProgrammer Check what connect() returns.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @hobbyProgrammer Check what connect() returns.

                      H Offline
                      H Offline
                      hobbyProgrammer
                      wrote on last edited by
                      #13

                      @jsulm it returns true

                      jsulmJ 1 Reply Last reply
                      0
                      • H hobbyProgrammer

                        @jsulm it returns true

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @hobbyProgrammer Do you actually have event loop running when you emit the signal?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved