Results 1 to 5 of 5

Thread: PyQt - Mapping multiple forms to a database

  1. #1
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default PyQt - Mapping multiple forms to a database

    I have a database with several tables which I want to access through a form. I am trying to access different tables using different tabs in a mainwindow. The issue is that the second mapping listed within the class doesn't seem to respond.

    I have the following fields defined at the top:
    SUPID, SUPTITLEID, SUPCOMPNAME, SUPFORENAME, SUPSURNAME, SUPADDLINE1, SUPADDLINE2, SUPADDTOWN, SUPADDCOUNTY, SUPADDPOSTCODE, SUPPHONE, SUPEMAIL, CUSTITLEID, CUSNAME, CUSFORENAME, CUSSURNAME, CUSDELADDLINE1, CUSDELADDLINE2, CUSDELADDTOWN, CUSDELADDCOUNTY, CUSDELADDPOSTCODE, CUSBILLADDLINE1, CUSBILLADDLINE2, CUSBILLADDTOWN, CUSBILLADDCOUNTY, CUSBILLADDPOSTCODE, CUSPHONE, CUSEMAIL, ID, NAME, = range(32)

    And then map to them using this syntax:
    self.supplierMapper.addMapping(self.supplierSurnam eEdit, SUPSURNAME)

    Is it because of the ordering for the fields at the top of the class. How do I make sure that one of the variables at the top of the class is mapped to the right field within the database.

    Any help would be hugely appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: PyQt - Mapping multiple forms to a database

    What is that supplierMapper exactly?

  3. #3
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQt - Mapping multiple forms to a database

    supplierMapper is a QDataWidgetMapper which maps variable to fields in a table.

    self.supplierMapper = QDataWidgetMapper(self)
    self.supplierMapper.setSubmitPolicy(QDataWidgetMap per.ManualSubmit)
    self.supplierMapper.setModel(self.suppliersModel)

  4. #4
    Join Date
    Apr 2008
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt - Mapping multiple forms to a database

    The order of your global constants must be the same as the creation order ofthe fields in your table. Also make sure you do not miss any fields in the declaration of your constants.

    The range you are defining is just allocating numbers to the variables which will correspond to the fields of you database.

  5. #5
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQt - Mapping multiple forms to a database

    Many thanks. Was wondering if you might be able to help with another question.

    I have multiple tables as previously mentioned. I want to load data from one table into a QLineEdit on a certain form based on the relationship. At the moment the relationship is created using a ComboBox and the following code:

    Qt Code:
    1. stockRelationModel = self.stockModel.relationModel(STOCKSUPPLIERID)
    2. self.stockSupplierNameComboxBox.setModel(stockRelationModel)
    3. self.stockSupplierNameComboxBox.setModelColumn(
    4. stockRelationModel.fieldIndex("companyName"))
    5. self.stockMapper.addMapping(self.stockSupplierNameComboxBox, STOCKSUPPLIERID)
    To copy to clipboard, switch view to plain text mode 

    Do you know how I can load other data from the table based on the STOCKSUPPLIERID variable. The other option would be if I could get it to load a form at the record specified by that ID.

    Can anyone give any help.

Similar Threads

  1. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 16:56

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.