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 when a form loads using signals and slots
QtWS25 Last Chance

connecting to database when a form loads using signals and slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcreatorformssignal & slotdatabase
4 Posts 4 Posters 1.7k Views
  • 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by Lasith
    #1

    I have 2 forms in my app namely MainWindow and Display! The MainWindow has the database connection method named getConnection (works successfully). When I fill database details and click a button in the MainWindow form the Display form is loaded! I want the Display form to have the getconnection method when the form loads! For that I use Signal and slot concept!

    following is my getconnection method(works)

    void MainWindow::getValues(){
    mydb.setDatabaseName(ui->sname->text());
    mydb.setUserName(ui->uname->text());
    mydb.setPassword(ui->pword->text());
    mydb.setPort(ui->port->text().toInt());
    mydb.setHostName(ui->ip->text());

    }

    The following code is from my Display.cpp

    Display::Display(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Display)
    {
    ui->setupUi(this);
    connect(ui->Display,SIGNAL(accepted()),MainWindow,SLOT(getConnection));

    }

    But the connection does not seem to exist! How can I adjust this to get the database connection?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Besides the fact that the connect statement is wrong (you can't connect a class), it should be in your MainWindow object. There's no reason for "Display" to have any knowledge of the MainWindow class.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Besides the fact that the connect statement is wrong (you can't connect a class), it should be in your MainWindow object. There's no reason for "Display" to have any knowledge of the MainWindow class.

        M Offline
        M Offline
        mostefa
        wrote on last edited by
        #3

        @SGaist said in connecting to database when a form loads using signals and slots:

        Hi,

        Besides the fact that the connect statement is wrong (you can't connect a class), it should be in your MainWindow object. There's no reason for "Display" to have any knowledge of the MainWindow class.

        I think that this post is duplicate

        https://forum.qt.io/topic/83307/qsqlquery-prepare-database-not-open

        ?

        kshegunovK 1 Reply Last reply
        0
        • M mostefa

          @SGaist said in connecting to database when a form loads using signals and slots:

          Hi,

          Besides the fact that the connect statement is wrong (you can't connect a class), it should be in your MainWindow object. There's no reason for "Display" to have any knowledge of the MainWindow class.

          I think that this post is duplicate

          https://forum.qt.io/topic/83307/qsqlquery-prepare-database-not-open

          ?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @mostefa said in connecting to database when a form loads using signals and slots:

          I think that this post is duplicate

          Strictly speaking it isn't, although it's quite similar.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved