Results 1 to 6 of 6

Thread: Sorry If this is a repost but something...

  1. #1
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Sorry If this is a repost but something...

    I am using a QT4.1.4 with the PSQL8.1.
    Sorry for reposting this problem but I am having problems with the setFilter
    method. I saw a plenty of posts in the forum but I just can't make it
    work?!
    Here is what I have in the constructor:

    filt::filt( QWidget * parent, Qt::WFlags f)
    : QDialog(parent, f)
    {
    //I have created a form with two buttons OK, CANCEL and a
    //table View named by default tableView. In the class I have
    //defined a model as a QSqlTableModel.

    setupUi(this);

    model = new QSqlTableModel(this);
    model->setTable("Krv");
    model->setFilter("GrupaID = 1");
    model->select();

    tableView->setModel(model);
    tableView->setVisible(true);


    }

    I have tried

    model->setFilter("GrupaID = /"1/""); -< for strings
    model->setFilter("Grupa = /"A+/"");
    model->setFilter("Grupa = 'A+'");

    I tried using a QString in the brackets, but...

    When I build my project I get a form with no data?!
    When I remove the setFilter line I got the data filled in the
    tableView. I tried all sort of filtering (I used it on numbers, int4,
    strings, with other tables but i am missing something).
    I tried almost all posts in forums but as I said i am missing
    something obviously...

    Here is a table structure:

    CREATE TABLE "Krv"
    (
    "GrupaID" int8 NOT NULL DEFAULT nextval('redni'::regclass),
    "Grupa" varchar(3),
    CONSTRAINT "Krv_pkey" PRIMARY KEY ("GrupaID")
    )
    WITHOUT OIDS;
    ALTER TABLE "Krv" OWNER TO postgres;

    And here is some table data:

    "6";"A-"
    "7";"A+"
    "8";"B-"
    "9";"B+"
    "10";"AB+"
    "11";"AB-"
    "12";"O-"
    "13";"O+"

  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: Sorry If this is a repost but something...

    Does the same query executed manually (i.e. using QSqlQuery) works? If not, what is the error? You can obtain the error text using QSqlError.

  3. #3
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Sorry If this is a repost but something...

    OK, I want to say that I am an absolute novice to QT programming and my C++ is below average. So I'll give my best to explain what is going on, and I'll try to implement what ever you say.
    After the
    setupUI(this) i wrote the following code:

    QSqlQuery query;
    query.exec("SELECT * FROM Krv");
    if (!query.isActive()){
    QMessageBox::warning(this, tr("Database Error"),
    query.lastError().text());
    } else {
    while (query.next()) {
    int gid = query.value(0).toInt();
    QString gr = query.value(1).toString();
    cout << qPrintable(gr) << ": " << gid << endl;
    }
    }


    And then I get the following error:

    ERROR: Relation "krv" does not exist
    QPSQL: Unable to create a query

    Is this correct?

  4. #4
    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: Sorry If this is a repost but something...

    No, it's not correct What if you change the table name from Krv to krv?

  5. The following user says thank you to wysota for this useful post:

    nnidza (3rd January 2007)

  6. #5
    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: Sorry If this is a repost but something...

    Quote Originally Posted by nnidza View Post
    query.exec("SELECT * FROM Krv");
    It should be:
    Qt Code:
    1. query.exec("SELECT * FROM \"Krv\"");
    To copy to clipboard, switch view to plain text mode 
    Once you started to use " around table and column names, you have to stick with it, because PostgreSQL converts all other identifiers to lowercase.

  7. The following user says thank you to jacek for this useful post:

    nnidza (3rd January 2007)

  8. #6
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Sorry If this is a repost but something...

    I've been using Microsoft SQL Server for years together with MS Access so I never thought this could be a problem:-(.
    Sorry once again for reposting...
    Thanks once again!

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.