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. How to get acess to a value from another dialog in mainwindow
Forum Updated to NodeBB v4.3 + New Features

How to get acess to a value from another dialog in mainwindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 625 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.
  • AzadshahrA Offline
    AzadshahrA Offline
    Azadshahr
    wrote on last edited by
    #1

    I have two QMainWindow in my app (ProcessList and MainWindow). ProcessList lists all running processes in my os in a QTableWidget. I wanted to select the PID in the QTableWidget and finally present it in my MainWindowApp dialog. How can I do that?

    I have defined a signal in my processlist.h file like the following one:

    signals:
        void pidAvailable(const int&);
    

    Then I defined the following method which a cell (PID cell) selected, it emits PID number like the following:

    void ProcessList::on_tableWidget_cellClicked(int row, int column)
    {
        int pid = ui->tableWidget->item(row, column)->text().toInt();
        emit pidAvailable(pid);
    }
    

    Then, I have defined the following slot in my MainWindow:

    public slots:
        void pidHandler(const int& arg_pid);
    

    Its implementation:

    void MainWindow::pidHandler(const int &arg_pid)
    {
        ui->lineEditProcessID->setText(QString::number(arg_pid));
    }
    

    Also, I don't know how should I connect these two things together in my application. However, How should I do now?

    Pl45m4P 1 Reply Last reply
    0
    • AzadshahrA Azadshahr

      I have two QMainWindow in my app (ProcessList and MainWindow). ProcessList lists all running processes in my os in a QTableWidget. I wanted to select the PID in the QTableWidget and finally present it in my MainWindowApp dialog. How can I do that?

      I have defined a signal in my processlist.h file like the following one:

      signals:
          void pidAvailable(const int&);
      

      Then I defined the following method which a cell (PID cell) selected, it emits PID number like the following:

      void ProcessList::on_tableWidget_cellClicked(int row, int column)
      {
          int pid = ui->tableWidget->item(row, column)->text().toInt();
          emit pidAvailable(pid);
      }
      

      Then, I have defined the following slot in my MainWindow:

      public slots:
          void pidHandler(const int& arg_pid);
      

      Its implementation:

      void MainWindow::pidHandler(const int &arg_pid)
      {
          ui->lineEditProcessID->setText(QString::number(arg_pid));
      }
      

      Also, I don't know how should I connect these two things together in my application. However, How should I do now?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Azadshahr

      What about

      connect(processList, &ProcessList::pidAvailable, this, &MainWindow::pidHandler);
      

      ?

      You need to have access to a pointer to ProcessList in MainWindow


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • AzadshahrA Offline
        AzadshahrA Offline
        Azadshahr
        wrote on last edited by
        #3
        This post is deleted!
        Pl45m4P 1 Reply Last reply
        0
        • AzadshahrA Azadshahr

          This post is deleted!

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @Azadshahr

          You need a pointer named processList (or how you want to name it) in your MainWindow class.

          At least one class needs to know about the other, otherwise you can not connect them.

          Store a pointer to ProcessList window in MainWindow for example.
          (Include processList.h and create member variable which holds pointer to processList)

          Easiest way would be to create your processList inside MainWindow.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          AzadshahrA 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @Azadshahr

            You need a pointer named processList (or how you want to name it) in your MainWindow class.

            At least one class needs to know about the other, otherwise you can not connect them.

            Store a pointer to ProcessList window in MainWindow for example.
            (Include processList.h and create member variable which holds pointer to processList)

            Easiest way would be to create your processList inside MainWindow.

            AzadshahrA Offline
            AzadshahrA Offline
            Azadshahr
            wrote on last edited by
            #5

            @Pl45m4 It compiled and run but I can't get the value emited and present it in my lineedit.

            Pl45m4P 1 Reply Last reply
            0
            • AzadshahrA Azadshahr

              @Pl45m4 It compiled and run but I can't get the value emited and present it in my lineedit.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @Azadshahr

              Debug and check what value your int has (assuming your connection is correct now) when emitting the signal.
              You can pass int by value. You don't need to pass a reference.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              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