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. connect table cell to QLabel
Forum Update on Monday, May 27th 2025

connect table cell to QLabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 515 Views
  • 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello,

    I have a QAbstractItemModel model where I create dynamically QLabels and rows by a pushButton, I am trying to connect text on column 0 to each QLabel, so that if I change for example text in position 0,1 QLabel labels[0] is automatically updated, I tried this:

    for(int i=0;i<model->rowCount(QModelIndex());i++){
                QModelIndex idx = model->index(i,0);
    
                connect(model->data(idx),SIGNAL(textChanged(const QString &)),&labels[i],SLOT(changeText()));
    
            }
    

    but it does not compiles, how could I solve this?

    Thank you everyone!

    JonBJ 1 Reply Last reply
    0
    • J jss193

      Hello,

      I have a QAbstractItemModel model where I create dynamically QLabels and rows by a pushButton, I am trying to connect text on column 0 to each QLabel, so that if I change for example text in position 0,1 QLabel labels[0] is automatically updated, I tried this:

      for(int i=0;i<model->rowCount(QModelIndex());i++){
                  QModelIndex idx = model->index(i,0);
      
                  connect(model->data(idx),SIGNAL(textChanged(const QString &)),&labels[i],SLOT(changeText()));
      
              }
      

      but it does not compiles, how could I solve this?

      Thank you everyone!

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

      @jss193

      but it does not compiles,

      It fails to compile but does not show any error message?

      1 Reply Last reply
      2
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        The signatures of the signal and slot do not match.

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

          Hi,

          Why are you using QLabels rather than an a QListView to show these texts ?

          From the looks of it, you are trying to connect QVariant objects which will not work.

          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
          • J Offline
            J Offline
            jss193
            wrote on last edited by
            #5

            @SGaist because I am adding dinamically qlabels that will be images not text.

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

              You can either use the DecorationRole to show them or a custom QStyledItemDelegate

              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

              • Login

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