Results 1 to 2 of 2

Thread: Qt fiedls to postgresql tables

  1. #1
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt fiedls to postgresql tables

    Hi there,

    I am going crazy about a simple thing I guess. I seeked broadly all over the QSQL pages to find the answer; but..

    My goal :
    Linking my Qt interface fields to my postgresql database.
    I read about QDataWidgetMapper but it doesn't fills my needs.
    ------------------------------------------------------------------------------
    Context :

    We will use my postgresql 's testing table.

    There is
    - a schema zero
    - a table one
    - a column two
    ------------------------------------------------------------------------------
    The code I have :
    I use Qt Creator and below is the code :

    Gestion.pro
    Qt Code:
    1. QT += core gui
    2. QT += sql
    3. TARGET = Gestion
    4. TEMPLATE = app
    5.  
    6.  
    7. SOURCES += main.cpp\
    8. mainwindow.cpp
    9.  
    10. HEADERS += mainwindow.h
    11.  
    12. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    My main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QCoreApplication>
    3. #include <QtSql/QtSql>
    4. #include <QtSql/QSqlDatabase>
    5. #include <QtSql/QSqlQuery>
    6. #include <iostream>
    7. #include "mainwindow.h"
    8.  
    9. #define q2c(string) string.toStdString()
    10.  
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. QApplication a(argc, argv);
    15.  
    16. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    17. db.setHostName("localhost");
    18. db.setPort(5433);
    19. db.setDatabaseName("totof");
    20. db.setUserName("postgres");
    21. db.setPassword("password");
    22.  
    23. db.open();
    24.  
    25. MainWindow w;
    26. w.show();
    27.  
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    and the mainwindows.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. mapper = new QDataWidgetMapper(this);
    11.  
    12. mapper->addMapping(ui->lineEdit,0);
    13. }
    14.  
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    To copy to clipboard, switch view to plain text mode 

    How could I tell the lineEdit to insert what i type in, into zero.un of my postgresql database ?

    I rely on you, since i am not good enough to make it on my own,

    LeHibou

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt fiedls to postgresql tables

    Did you connect the widget mapper to a model?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 13th July 2010, 05:17
  2. Replies: 1
    Last Post: 16th May 2010, 19:25
  3. tables
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 15:17
  4. nested tables
    By Jeroen van der Waal in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2007, 17:12

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.