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. Role in setData has no effect

Role in setData has no effect

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 782 Views 2 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have the following in my .h file:

      bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) ;  
    

    in .cpp:
    I have the function:

    bool FixDb::setData(const QModelIndex &index, const QVariant &value, int role )
    {
        if(role == Qt::EditRole)
            {
                qDebug()     << "Entered setData bool.";
                int rowFix = index.row ();
                int colFix = index.column ();
    
                qDebug() << "Setdata row: " << rowFix;
                qDebug() << "Setdata col: " << colFix;
            }
        return true;
    }
    

    bool setData is called from an other function:

    void FixDb::on_tableView_Fix_doubleClicked(const QModelIndex &index)
    {
        int row = index.row ();
        int column = index.column ();
        qDebug() << "Fix Index: " << "(" << row <<"," << column << ")";
    
        QModelIndex fixIndex(index.model()->index(index.row(), 0, index.parent()));
        qDebug() << fixIndex.data(Qt::DisplayRole);
        QVariant v(fixIndex.data(Qt::DisplayRole));
        fixID = v.toString ();
        qDebug () << "Fix ID: " << fixID;
    
        QModelIndex fixItemIndex(index.model ()->index (row,column, index.parent()));
        qDebug() << fixItemIndex.data (Qt::DisplayRole);
        QVariant fixV;
        fixV = fixItemIndex.data (Qt::DisplayRole);
        itemToFix = fixV.toString ();
    
        qDebug() << "Item to fix: " << itemToFix;
    
        QSqlQuery query_getImage;
        query_getImage.prepare ("SELECT Pic FROM Items WHERE ID = :FriendID");
        query_getImage.bindValue (":FriendID",FriendID);
    
        setData(index, value, role);
    

    In the .h the editRole is set, but clearly it doesn't transfer to the actual bool function in the cpp file as processing does not enter

    if(role == Qt::EditRole)
    

    It jumps directly to the return true. Why don't I have the editRole set in the actual function? Thank you.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @gabor53 You are passing some role here:

      setData(index, value, role);
      

      Try without passing so that it takes the default value.

      setData(index, value);
      

      157

      G 1 Reply Last reply
      3
      • p3c0P p3c0

        @gabor53 You are passing some role here:

        setData(index, value, role);
        

        Try without passing so that it takes the default value.

        setData(index, value);
        
        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @p3c0
        Thank you.

        setData(index, value);
        

        worked.

        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