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. Connecting to Database using .ui files.
Forum Updated to NodeBB v4.3 + New Features

Connecting to Database using .ui files.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.5k Views 1 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
    Gimpit
    wrote on last edited by
    #1

    I am having trouble connecting or configuring a single tableView between two or more connections. I am sure this can done but my main problem is configuring each ui->pushButton to connect to model tableView.
    Project description:
    A mainwindow consisting of three pushButtons and one TableView.
    Which is connected to a single database with three tables.
    I would like to be able to press each pushButton and have the tableView reflect the matching table.
    pushButton_1 to view table1
    pushButton_2 to view table2
    pushButton_3 to view table3
    I could hard code the connections but I would rather like to use the Designer ui's.
    And I am also trying to make this happen without using any other dialogs besides mainwindow.

    If this is possible, please point me to the correct documentation.

    Thank you,
    Jay From Seattle

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      I don't think you can do that. The ui files are declarative file related to the GUI, while what you need is something that is not tied to the GUI (database connection). Of course you can pass forth and back the database connection to the gui (ui forms) but you have to make it in the main or somewhere else. Moreover you don't have to hardcode connection parameters, you can get them from settings or as line arguments.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        It cannot be done out of the box, as Qt Designer isn't even aware of the Qt SQL module. The only solution would be a custom widget wrapped in a Qt Designer plugin. But I doubt it's worth the effort.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gimpit
          wrote on last edited by
          #4

          Using the UI file and connecting variables to the form's variables

          So far I have found out that:

          After I have created my UI form "someForm"
          and If I add the following statement before my class definition:

          "namespace Ui {
          class SomeClass;
          }"

          And I declare the UI form privately in SomeClass by:

          private:
          "Ui::someForm *ui;"

          This will enable me to access each UI element of the form by passing the values:
          ui->someWidget;

          (The following function calculates an hourly wage and puts the calculation into a total QSpinBox)

          "double SomeClass::updateTotal()
          {
          double total = (ui->rateSpinBox->value() * ui->hourSpinBox->value());

          ui->totalSpinBox->setValue(total);
          

          }"

          Now I have to figure how to use this in conjunction with a QTableView.

          Thanks,

          Jay

          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