Results 1 to 2 of 2

Thread: How to update database with dynamically created widget values

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to update database with dynamically created widget values

    I want to update my database with values from widgets that are created dynamically. I can get the values from the widgets but to link and update dynamic values with the attributes in my database is the problem.

    Here is my code:

    Qt Code:
    1. {
    2. ui->setupUi(this);
    3. fb = new FrmBuilder(ui);
    4.  
    5. QFileInfo checkFile(Path_to_DB);
    6.  
    7. if(checkFile.isWritable())
    8. {
    9. if(db.open())
    10. {
    11. qDebug() << "Connected to database file";
    12. }
    13. }else{
    14. qDebug() << "Database file not found";
    15. }
    16. fb->buildFrm();
    17. }
    18.  
    19. void MainWindow::on_pushButton_clicked()
    20. {
    21. fb->display();
    22. }
    To copy to clipboard, switch view to plain text mode 

    class FrmBuilder.cpp:

    Qt Code:
    1. void FrmBuilder::buildFrm()
    2. {
    3.  
    4. if (qry.exec("SELECT persons FROM candidate"))
    5. {
    6. while(qry.next())
    7. {
    8. qDebug() << qry.value(0).toString();
    9. QString person = qry.record().value(0).toString();
    10. label = new QLabel(QString(person));
    11. spinbox = new QSpinBox;
    12. spinBoxes << spinbox;
    13.  
    14. label->setGeometry(0,0,80,41);
    15.  
    16. for(int i = 0; i<spinBoxes.size();i++){
    17. myUi->verticalLayout->addWidget(label);
    18. myUi->verticalLayout_2->addWidget(spinBoxes[i],0,0);
    19. }
    20. }
    21. }
    22. else
    23. {
    24. qDebug() << qry.lastError();
    25. }
    26. qry.clear();
    27. }
    28.  
    29. void FrmBuilder::display()
    30. {
    31. for(int i = 0; i<spinBoxes.size(); i++){
    32. values << spinBoxes[i]->value();
    33. qDebug() << values[i];
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

    So that code basically creates a widget form with a label and spinbox based on dynamic user line edits. Reads the values from the created form and prints them.

    I just want to know how I will link this value to the specific label (person) in my database so it increments it.
    Last edited by Cyrebo; 22nd April 2013 at 22:58.

Similar Threads

  1. use value from dynamically created widget in a slot
    By Cyrebo in forum Qt Programming
    Replies: 55
    Last Post: 23rd April 2013, 14:51
  2. Replies: 4
    Last Post: 8th April 2013, 04:19
  3. Accessing Dynamically created Checkboxe
    By premroxx in forum Newbie
    Replies: 1
    Last Post: 6th November 2012, 07:14
  4. Replies: 9
    Last Post: 2nd November 2011, 09:12
  5. Dynamically created buttons.
    By Tomasz in forum Newbie
    Replies: 26
    Last Post: 2nd December 2010, 09:40

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.