Results 1 to 3 of 3

Thread: QSqlQueryModel insertColumn() returns false

  1. #1
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QSqlQueryModel insertColumn() returns false

    I am trying to add a new column to a QSqlQueryModel and populate it with data not related to its database. There are 2 columns from the database query. I tried the following code to check if column insertion was successful.

    Qt Code:
    1. QModelIndex testIndex = atsFieldModel->index(1, 1);
    2. if(atsFieldModel->insertColumn(2, testIndex.parent()))
    3. QMessageBox::information(this, tr("Successful"), tr("column inserted!"));
    To copy to clipboard, switch view to plain text mode 

    But the messagebox does not appear. I also used insertColumns() method but it didn't work either. Please explain to me what I did wrong here. Thank you.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel insertColumn() returns false

    From QSqlQueryModel::insertColumns():
    The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.
    EDIT: Commented without trying your code. Looks like testIndex.parent() does return an invalid QModelIndex. Try:
    Qt Code:
    1. atsFieldModel->insertColumn(2)
    To copy to clipboard, switch view to plain text mode 
    Both work for me.
    Last edited by norobro; 25th March 2011 at 15:20.

  3. #3
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQueryModel insertColumn() returns false

    OMG, it was right there in the documentation, I must have missed it. It worked perfectly. Thanx a lot norobro

Similar Threads

  1. Qimage::save returns false in release
    By CCTeam in forum Qt Programming
    Replies: 5
    Last Post: 26th May 2010, 17:35
  2. Strange error: doc.setContent(data) returns false
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2009, 01:38
  3. QSslSocke::supportSsl() returns false
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2008, 18:51
  4. QSqlQuery::isValid returns false
    By mismael85 in forum Qt Programming
    Replies: 24
    Last Post: 7th September 2008, 23:43
  5. connect returns false
    By krivenok in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 20:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.