TableView input rows strategy like invoice detail input?



  • Hi,
    Let's say, I have a program to input invoice in database. I want to input invoce detail rows in TableView. I used QSqlRelationalTableModel. But when I connect signal to model like below then relations comboboxes don't appear. But when I commented below line than I can double click and combobox which related database table opens normally.

    What is the problem and What do you suggest to use invoice details like input?...

    Regards,
    Mucip:)

     this->modelFisDetay = new QSqlRelationalTableModel(this, baglanti::mdb2());
    
           connect(ui->tVFisDetay->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
                   this, SLOT(satirKaydet()));
    

  • Lifetime Qt Champion

    Hi,

    You should give more details about how you setup your database access.



  • Hi,
    My connection code like below but I do not think that this problem is about connection?

    How can I write new line to SQLite database with QSqlRelationalTableModel?

    My connection code is:

    //Burada SQLite bağlantısı kuruluyor!
               db2 = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE","sqlite"));
               db2->setDatabaseName(":memory:");
               if (!db2->open()) {
                   QMessageBox::critical(nullptr, "SQLite Veritabanına ulaşılamadı!",
                       "Veritabanına kapalı veya ulaşılamıyor!\n\n"
                                "Program sonlanıyor.", QMessageBox::Ok);
                   return false;
               }
    
    

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    How do you setup your database ?

    Since it's an in-mermoy database, it means it won't survive between two application runs so you have to re-create all the tables each time you start your application.



  • Dear @SGaist,
    As I guess, It's not about db connection style.
    When I open the form I re-create or flush DB if exist.

    I want to add new line below of Tableview. Because of it connected to memory db. I insert one line to memory db and reassign qtableview to memory db.
    I think I made something wrong in this step! What is the system of add one new line to qtableview which is linked to DB?!
    This is the problem!.... :(

    I all want to do the invoice detail input like this post.

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    It's not the job of the view to add new rows. Take a look at QSqlTableModel::insertRecord.



  • Hi @SGaist ,
    Well, what about the currentRowChanged signal on tableview? I couldn't catch it?

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    This is when a row has changed, you asked for adding a new row.



  • Dear @SGaist ,
    Ok. I will give up to use db connection with memory DB.
    I will use like below
    QStandardItemModel model(4, 2);

    And finally I transfer theese data to DB when close form or push save button.

    Well, Normally if you push down arrow at the end of the tableview it add one new row at the bottom. How can I get this? By which signal/slot?...

    Regards,
    Mucip:)



  • Hi, @SGaist
    Well I changed to use QStandardItemModel.
    But How can I delete pointer? Ofcourse I can add delete in formClose signal but where can I add "this" parameter

    this->modelFisDetay = new QStandardItemModel(10,4);
    

    Normally it should be:

    this->modelTableBelgeTip = new QSqlQueryModel(this);
    

    But I can not add this to QStandardItemModel???

    Regards,
    Mucip:)


  • Qt Champions 2017

    Hi
    Yes you can :)
    QStandardItemModel(int rows, int columns, QObject * parent = 0)
    Parent just go last.



  • Dear @mrjj ,
    Great... Thanks... ;-)

    Regards,
    Mucip:)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.