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. SQL Database Connection and Comparison
Forum Updated to NodeBB v4.3 + New Features

SQL Database Connection and Comparison

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 825 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.
  • C Offline
    C Offline
    cprogcoder
    wrote on last edited by
    #1

    Hello,

    i would to ask about a qlineedit a surname of a current database.
    If the surname exists, it should show it over a QTableView.

    I made it for the surname "Mueller" but how can I generalize it or compare it
    with the other surnames in the database.

    If f you want to support,please give me the code as sample or directly.

    Thanks

    void Suchen::on_SucheStart_clicked()
    {
    
        QString suchen1;
        QString sqlAbfrage = "anachname = '" + suchen1 + "'";
    
        suchen1 = ui->lineEditname->text();
        sqlAbfrage = suchen1;
    
        QMessageBox::information(this,"Anfrage",suchen1);
    
        //wenn eine Verbindung zu Datenbank besteht
        if (dbVerbunden == true)
        {
            if (suchen1 == "Mueller" )
    
            //sqlAbfrage == "Mueller"
            //suchen == ui->lineEditname->text()
    
            {
            //den Dialog anzeigen
            suchenliste *formListeSuchen = new suchenliste();
            formListeSuchen->show();
            }
    
            else
            //den Dialog anzeigen
            QMessageBox::information(this,"Nachname Suche","keine Ergebnisse");
    
    
        }
    
    

    Code about SQL

    suchenliste::suchenliste()
    {
    
        //QString sqlAbfrage;
        QString suchen;
        suchen = "Strobelt";
    
        //den Fenstertitel setzen
        setWindowTitle("Suchen Anzeige");
        //das Modell erstellen
        QSqlTableModel *modell = new QSqlTableModel(this);
        //die Tabelle setzen
        modell->setTable("adressen");
        //"anachname" == sqlAbfrage
        modell->setFilter("anachname = 'Mueller'"); //"anachname = 'Mueller'"
    
        //die Texte für die Spaltenköpfe setzen
        modell->setHeaderData(0, Qt::Horizontal, "ID");
        modell->setHeaderData(1, Qt::Horizontal, "Vorname");
        modell->setHeaderData(2, Qt::Horizontal, "Name");
        modell->setHeaderData(3, Qt::Horizontal, "Strasse");
        modell->setHeaderData(4, Qt::Horizontal, "PLZ");
        modell->setHeaderData(5, Qt::Horizontal, "Ort");
        modell->setHeaderData(6, Qt::Horizontal, "Telefon");
    
        //die Daten beschaffen
        modell->select();
    
        //die TableView erstellen
        QTableView *ansicht = new QTableView(this);
        //mit dem Modell verbinden
        ansicht->setModel(modell);
        //die Breite der Spalten an den Inhalt anpassen
        ansicht->resizeColumnsToContents();
        //die Größe setzen
        ansicht->resize(500,300);
    
    
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean get the content of your QLineEdit and do a SELECT query on your database ?

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cprogcoder
        wrote on last edited by
        #3

        Yes, I mean to get the information from the QLine edit and then select it from the SQL Database.

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

          Then why don't you just pass the value from that QLineEdit as a parameter to suchenliste ?

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

          1 Reply Last reply
          1

          • Login

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