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. Passing data to a new window class.
Forum Updated to NodeBB v4.3 + New Features

Passing data to a new window class.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 247 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.
  • D Offline
    D Offline
    dencla
    wrote on last edited by
    #1

    I have an application that I am trying to pass a value to a new window that I'm trying to show. See below;

    MainWindow    QModelIndex SelectedSchedule;
    
    

    I want to pass the current value of SelectedSchedule to OrderEd.

    void SchedulePanel::on_OrderEntry_PB_clicked()
    {
        order *OrderEd;
        OrderEd = new order ();
        OrderEd->show();
    
    }
    
    I need to retrieve the row of data selected in the schedule view on the MainWindow. Is there a good way to pass this each time I open this window?
    Thanks
    
    jsulmJ Pl45m4P 2 Replies Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher moved this topic from Qt Creator and other tools on
    • D dencla

      I have an application that I am trying to pass a value to a new window that I'm trying to show. See below;

      MainWindow    QModelIndex SelectedSchedule;
      
      

      I want to pass the current value of SelectedSchedule to OrderEd.

      void SchedulePanel::on_OrderEntry_PB_clicked()
      {
          order *OrderEd;
          OrderEd = new order ();
          OrderEd->show();
      
      }
      
      I need to retrieve the row of data selected in the schedule view on the MainWindow. Is there a good way to pass this each time I open this window?
      Thanks
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @dencla What exactly is the problem? The piece of code you provided does not really help to understand where you're stuck. Your main window is a C++ class, so it can be used like any other C++ class. Implement an interface there to pass it needed data or get data from it.

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

      1 Reply Last reply
      2
      • D dencla

        I have an application that I am trying to pass a value to a new window that I'm trying to show. See below;

        MainWindow    QModelIndex SelectedSchedule;
        
        

        I want to pass the current value of SelectedSchedule to OrderEd.

        void SchedulePanel::on_OrderEntry_PB_clicked()
        {
            order *OrderEd;
            OrderEd = new order ();
            OrderEd->show();
        
        }
        
        I need to retrieve the row of data selected in the schedule view on the MainWindow. Is there a good way to pass this each time I open this window?
        Thanks
        
        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @dencla said in Passing data to a new window class.:

        I want to pass the current value of SelectedSchedule to OrderEd.

        Access the model at your SelectedSchedule index and use some function to retrieve the data at index the way you want it.
        There is no general function in custom models to return row data because as the name suggests, each model is different. So you have to provide your own interface to return data as mentioned by @jsulm


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

        ~E. W. Dijkstra

        D 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @dencla said in Passing data to a new window class.:

          I want to pass the current value of SelectedSchedule to OrderEd.

          Access the model at your SelectedSchedule index and use some function to retrieve the data at index the way you want it.
          There is no general function in custom models to return row data because as the name suggests, each model is different. So you have to provide your own interface to return data as mentioned by @jsulm

          D Offline
          D Offline
          dencla
          wrote on last edited by
          #4

          @Pl45m4 Thank You for your feedback. I am learning QT and would like to be able to do this;

          void SchedulePanel::on_OrderEntry_PB_clicked()
          {
            
              order *OrderEd;
              OrderEd = new order ();
              OrderEd->show(QModelIndex SelectedSchedule);
          
          }
          
          
          

          Is That possible?
          Thanks

          Pl45m4P 1 Reply Last reply
          0
          • D dencla

            @Pl45m4 Thank You for your feedback. I am learning QT and would like to be able to do this;

            void SchedulePanel::on_OrderEntry_PB_clicked()
            {
              
                order *OrderEd;
                OrderEd = new order ();
                OrderEd->show(QModelIndex SelectedSchedule);
            
            }
            
            
            

            Is That possible?
            Thanks

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

            @dencla said in Passing data to a new window class.:

            Is That possible?

            Not exactly the way you write it but in general, yes.
            Like @jsulm said, you have to write your own interface to interact with your order class.
            You have a weird naming, by the way... usually you would write classes with capital first letter and object names/variables with lower case.
            Anyway, add a function with your desired signature to your order class, like

            void order::show(QModelIndex index)
            {
                // do something with index
            
                // then call QWidget's show() function
                show();
            }
            
            void SchedulePanel::on_OrderEntry_PB_clicked()
            {
                // get model index from selection model
                QModelIndex selection = yourView->selectionModel()->selectedIndexes();
            
                // make order a member of SchedulePanel to avoid memory leaking
                // or make it child of SchedulePanel... depends on what class/type order is...
                
                // show it using your function, e.g.: 
                OrderEd->show(selection);
            }
            

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

            ~E. W. Dijkstra

            D 1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @dencla said in Passing data to a new window class.:

              Is That possible?

              Not exactly the way you write it but in general, yes.
              Like @jsulm said, you have to write your own interface to interact with your order class.
              You have a weird naming, by the way... usually you would write classes with capital first letter and object names/variables with lower case.
              Anyway, add a function with your desired signature to your order class, like

              void order::show(QModelIndex index)
              {
                  // do something with index
              
                  // then call QWidget's show() function
                  show();
              }
              
              void SchedulePanel::on_OrderEntry_PB_clicked()
              {
                  // get model index from selection model
                  QModelIndex selection = yourView->selectionModel()->selectedIndexes();
              
                  // make order a member of SchedulePanel to avoid memory leaking
                  // or make it child of SchedulePanel... depends on what class/type order is...
                  
                  // show it using your function, e.g.: 
                  OrderEd->show(selection);
              }
              
              D Offline
              D Offline
              dencla
              wrote on last edited by
              #6

              @Pl45m4 Thank you for your feedback. I will give it a try.

              1 Reply Last reply
              0
              • D dencla has marked this topic as solved on

              • Login

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