Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. suggestions for repeating display views
Qt 6.11 is out! See what's new in the release blog

suggestions for repeating display views

Scheduled Pinned Locked Moved Solved Brainstorm
36 Posts 5 Posters 24.6k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    The most minimal I can think of a QListView and a QLabel for displaying the information.

    Can you give more details about your setup ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • mzimmersM mzimmers

      I couldn't think of a better way of phrasing my title. I'm writing an app that controls and reports on devices that are connected wirelessly. The needs are modest, but there's a bit of wrinkle in that the customer may have 1 or 100 of these wireless devices.

      I need a way to allow him to run through a list of these devices, and select one. Doing so would then give him a details screen with which he can perform other actions on the selected device.

      Would this be a good use of QStackedWidgets, or is there more appropriate construct for this?

      Thanks...

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #3

      @mzimmers
      You could, but it doesn't sound like it scales, what if there were 10,000 of these devices? Eventually there's a memory price to pay.

      But are you going to create a separate widget for each device? Won't the displays be similar? So you'll want to write code which lets user pick which device and then show a "shared" widget for the information?

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #4

        More information: the main window will contain a list/table of active devices on the network. Some very summary information (MAC address, device ID, last communication time) will appear in this table. When the user wants to get more information or to configure a particular device, he'll select it from this list.

        At this point, the display will change to a details view. There will be more information and several controls, but everything will pertain to just one device. JonB's point is valid about this probably using resources unnecessarily.

        I'll have to store a fair amount of data (some time period for each device) but I guess there's no reason the details UI needs to be replicated.

        SGaist: the list/label will be fine for the overview display (I'll use a table instead of a view), but I'll need another display for the details view.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Keep all your device information in a model so you can easily and quickly get them.

          Then when your user selects a device, Load the corresponding data from your model and show it in the QLabel.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #6

            I'm not sure I understand what you're recommending -- are you proposing that I use a single QLabel object for the entirety of my details display?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #7

              If you are only showing one device details at a time, yes. Just update the content of the label with what corresponds to the selected device.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #8

                The details view as I intend it will contain quite a bit of information. There will be ~10-15 fields, all of which can be modified by the user. There will also be a few push buttons to send other commands to the target device.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Makes me thinking about the QtSQL module Book example.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  3
                  • mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #10

                    Thanks for the reference. I've taken some of that example and adapted it.

                    So, to summarize, I have a QTableView that is associated with a QAbstractItemModel. The table reveals a few details about all the devices (rows) found. Now I'd like to display some additional detail about any device that the user selects.

                    A very simple start would be to display the MAC address in a QLineEdit when the user selects a row. I can envision a way to do this, but it's cumbersome and indirect (signalling the model to extract the information and signal it back to the widget). Can someone inform me of a preferred method to do this?

                    Thanks...

                    JonBJ kshegunovK 2 Replies Last reply
                    0
                    • mzimmersM mzimmers

                      Thanks for the reference. I've taken some of that example and adapted it.

                      So, to summarize, I have a QTableView that is associated with a QAbstractItemModel. The table reveals a few details about all the devices (rows) found. Now I'd like to display some additional detail about any device that the user selects.

                      A very simple start would be to display the MAC address in a QLineEdit when the user selects a row. I can envision a way to do this, but it's cumbersome and indirect (signalling the model to extract the information and signal it back to the widget). Can someone inform me of a preferred method to do this?

                      Thanks...

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #11

                      @mzimmers

                      but it's cumbersome and indirect (signalling the model to extract the information and signal it back to the widget)

                      Why? What do you have in mind by "indirect" & "signalling"? You haven't mentioned threads anywhere, so assuming your UI, view & model are all in the same thread where is there any "signalling" involved (unless you mean the row selected signal, but that does not matter)?

                      You just retrieve the data via QAbstractItemModel::data() and plonk it into your widget(s), explicitly.

                      Depending, you can already have retrieved the "additional detail" into your model without having to display it in the QTableView, so you can access it without having to do work at that instant if you prefer (perhaps not relevant for your device-model, but often the case when it's a database-model).

                      1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        Thanks for the reference. I've taken some of that example and adapted it.

                        So, to summarize, I have a QTableView that is associated with a QAbstractItemModel. The table reveals a few details about all the devices (rows) found. Now I'd like to display some additional detail about any device that the user selects.

                        A very simple start would be to display the MAC address in a QLineEdit when the user selects a row. I can envision a way to do this, but it's cumbersome and indirect (signalling the model to extract the information and signal it back to the widget). Can someone inform me of a preferred method to do this?

                        Thanks...

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #12

                        Well, I'd just fill the model data as it comes. And it'd come as the selection of the selection model changes ... I think just subscribing to the QItemSelectionModel::selectionChanged signal should be enough, no?

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        2
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by mzimmers
                          #13

                          Here's what I'm trying to do in my display:

                          // in my c'tor.
                              QObject::connect(ui->tableView->selectionModel(), QItemSelectionModel::currentRowChanged, this, &Widget::updateDetails);
                          }
                          
                          void Widget::updateDetails(QModelIndex i)
                          {
                              int row = i.row();
                              QVariant qv;
                              QString s;
                              QModelIndex qmi;
                              qmi = m_model->getModel()->index(row, DEV_MACADDR, QModelIndex());
                              qv = m_model->getModel()->data(qmi, DEV_MACADDR);
                              s = qv.toString();
                              ui->macAddr->setText(s);
                          
                              qmi = m_model->getModel()->index(row, DEV_DEVNAME, QModelIndex());
                              qv = m_model->getModel()->data(qmi, DEV_DEVNAME);
                              s = qv.toString();
                              ui->devName->setText(s);
                          
                              qmi = m_model->getModel()->index(row, DEV_LATEST_HB, QModelIndex());
                              qv = m_model->getModel()->data(qmi, DEV_LATEST_HB);
                              s = qv.toString();
                              ui->heartbeat->setText(s);
                          

                          I'm sure this isn't the best way to do this (particularly since it doesn't work), but in any event, the first assignment of qv works, but the others give qv an invalid value. What am I doing wrong?

                          EDIT: OK, I just realized I shouldn't be using the 2nd argument to the data() call. It's working now. Not ready to mark this solved yet, though, as I'm going to have other questions in a bit.

                          Thanks...

                          1 Reply Last reply
                          0
                          • mzimmersM Offline
                            mzimmersM Offline
                            mzimmers
                            wrote on last edited by
                            #14

                            So far, I've been experimenting entirely with QStrings as elements in my model, like this:

                            struct DeviceDetails
                            {
                                uint8_t macAddr[6];
                                char devName[25];
                            ...
                            } d;
                            QAbstractItemModel *m_model;
                            ...   
                             m_model->setData(m_model->index(row, DEV_DEVNAME), d.devName); /
                            

                            I'm now trying to work with other data types, such as the macAddr, but I can't figure out how to do this. This is what I'm trying to do (but doesn't compile):

                                m_model->setData(m_model->index(row, DEV_MACADDR), d.macAddr);
                            

                            How do I do this? Thanks...

                            kshegunovK 1 Reply Last reply
                            0
                            • mzimmersM mzimmers

                              So far, I've been experimenting entirely with QStrings as elements in my model, like this:

                              struct DeviceDetails
                              {
                                  uint8_t macAddr[6];
                                  char devName[25];
                              ...
                              } d;
                              QAbstractItemModel *m_model;
                              ...   
                               m_model->setData(m_model->index(row, DEV_DEVNAME), d.devName); /
                              

                              I'm now trying to work with other data types, such as the macAddr, but I can't figure out how to do this. This is what I'm trying to do (but doesn't compile):

                                  m_model->setData(m_model->index(row, DEV_MACADDR), d.macAddr);
                              

                              How do I do this? Thanks...

                              kshegunovK Offline
                              kshegunovK Offline
                              kshegunov
                              Moderators
                              wrote on last edited by
                              #15

                              @mzimmers said in suggestions for repeating display views:

                              but doesn't compile

                              With what error?
                              I could imagine QVariant isn't aware of how to serialize that type, but that's just a speculation at this point.

                              Read and abide by the Qt Code of Conduct

                              1 Reply Last reply
                              0
                              • mzimmersM Offline
                                mzimmersM Offline
                                mzimmers
                                wrote on last edited by
                                #16
                                C:\Qt\5.10.1\mingw53_32\include\QtCore\qvariant.h:471: error: 'QVariant::QVariant(void*)' is private
                                     inline QVariant(void *) Q_DECL_EQ_DELETE;
                                            ^
                                

                                and:

                                C:\Users\MZimmers\CD desktop apps\Qt projects\wb_utility\model.cpp:36: error: use of deleted function 'QVariant::QVariant(void*)'
                                
                                kshegunovK VRoninV 2 Replies Last reply
                                0
                                • mzimmersM mzimmers
                                  C:\Qt\5.10.1\mingw53_32\include\QtCore\qvariant.h:471: error: 'QVariant::QVariant(void*)' is private
                                       inline QVariant(void *) Q_DECL_EQ_DELETE;
                                              ^
                                  

                                  and:

                                  C:\Users\MZimmers\CD desktop apps\Qt projects\wb_utility\model.cpp:36: error: use of deleted function 'QVariant::QVariant(void*)'
                                  
                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on last edited by
                                  #17

                                  Well, I suggest you convert d.macAddr to QString before you pass it to setData ...

                                  Read and abide by the Qt Code of Conduct

                                  1 Reply Last reply
                                  2
                                  • mzimmersM Offline
                                    mzimmersM Offline
                                    mzimmers
                                    wrote on last edited by
                                    #18
                                    This post is deleted!
                                    1 Reply Last reply
                                    0
                                    • mzimmersM mzimmers
                                      C:\Qt\5.10.1\mingw53_32\include\QtCore\qvariant.h:471: error: 'QVariant::QVariant(void*)' is private
                                           inline QVariant(void *) Q_DECL_EQ_DELETE;
                                                  ^
                                      

                                      and:

                                      C:\Users\MZimmers\CD desktop apps\Qt projects\wb_utility\model.cpp:36: error: use of deleted function 'QVariant::QVariant(void*)'
                                      
                                      VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on last edited by VRonin
                                      #19

                                      @mzimmers said in suggestions for repeating display views:

                                      'QVariant::QVariant(void*)' is private

                                      That is a "safeguard" operator to avoid people using pointers to non-QObjects into a QVariant.
                                      Basically macAddr is of type unsigned char* the d will still own the data into d.macAddr and will delete it when it goes out of scope. QVariant needs to own the data and know how to delete it. you should be able to hack your way around it by using a smart pointer but it's probably much easier to store it in a Qt container like QByteArray
                                      m_model->setData(m_model->index(row, DEV_MACADDR), QByteArray(d.macAddr,sizeof(d.macAddr));

                                      P.S.
                                      If the compiler complains about signed/unsigned you can use:
                                      QByteArray(static_cast<char*>(d.macAddr),sizeof(d.macAddr))

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      mzimmersM 1 Reply Last reply
                                      3
                                      • VRoninV VRonin

                                        @mzimmers said in suggestions for repeating display views:

                                        'QVariant::QVariant(void*)' is private

                                        That is a "safeguard" operator to avoid people using pointers to non-QObjects into a QVariant.
                                        Basically macAddr is of type unsigned char* the d will still own the data into d.macAddr and will delete it when it goes out of scope. QVariant needs to own the data and know how to delete it. you should be able to hack your way around it by using a smart pointer but it's probably much easier to store it in a Qt container like QByteArray
                                        m_model->setData(m_model->index(row, DEV_MACADDR), QByteArray(d.macAddr,sizeof(d.macAddr));

                                        P.S.
                                        If the compiler complains about signed/unsigned you can use:
                                        QByteArray(static_cast<char*>(d.macAddr),sizeof(d.macAddr))

                                        mzimmersM Offline
                                        mzimmersM Offline
                                        mzimmers
                                        wrote on last edited by
                                        #20

                                        @VRonin ah that explains it (in fact, that's exactly what I was trying to do).

                                        I like your idea of changing my char array into QByteArray, but there's a snag - I'm attempting to use the same C struct for my target device as my host app, which restricts me to C++11 types.

                                        JonBJ 1 Reply Last reply
                                        0
                                        • mzimmersM mzimmers

                                          @VRonin ah that explains it (in fact, that's exactly what I was trying to do).

                                          I like your idea of changing my char array into QByteArray, but there's a snag - I'm attempting to use the same C struct for my target device as my host app, which restricts me to C++11 types.

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by
                                          #21

                                          @mzimmers
                                          But @VRonin is only asking you to make a copy into a QByteArray for passing to m_model->setData(); you're not changing what is actually in your struct d. So how does that affect your use of the struct in the two apps?

                                          1 Reply Last reply
                                          3

                                          • Login

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