Results 1 to 6 of 6

Thread: error...

  1. #1
    Join Date
    May 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default error...

    hi, i got this at app output...


    QObject::installEventFilter(): Cannot filter events for objects in a different thread.

    no error while i try to build my program...its shows that after i build.. but
    what it means?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error...

    You are probably trying to install filter on some object, which is part of another thread..
    If you show the code, may be we can tell better

  3. #3
    Join Date
    May 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error...

    well i dont understand what it means..huhuh

    now i try write database using progrmmg..

    this my mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QWidget>
    6.  
    7. class QComboBox;
    8. class QLabel;
    9. class QLineEdit;
    10. class QTextEdit;
    11.  
    12. class MainWindow : public QMainWindow {
    13. Q_OBJECT
    14. public:
    15. MainWindow(QWidget *parent = 0);
    16.  
    17. private slots:
    18. void updateButton(int row);
    19.  
    20. private:
    21. void setupModel();
    22.  
    23. QLabel *label;
    24. QTextEdit *textEdit;
    25. QComboBox *comboBox;
    26. QPushButton *pushButton;
    27.  
    28. QItemSelectionModel *selectionModel;
    29.  
    30.  
    31.  
    32. };
    33.  
    34. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 




    mainwindow.cpp


    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QSqlTableModel>
    4. #include <QDataWidgetMapper>
    5. #include <QSqlRelationalDelegate>
    6. #include <QSqlRelationalTableModel>
    7. #include <QMessageBox>
    8. #include <QSqlQuery>
    9.  
    10. MainWindow::MainWindow(QWidget *parent) :
    11. QMainWindow(parent)
    12.  
    13. {
    14. setupModel();
    15.  
    16. mapper = new QDataWidgetMapper(this);
    17. mapper->setModel(model);
    18. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    19. mapper->addMapping(comboBox, model->fieldIndex("name"));
    20. mapper->addMapping(textEdit, model->fieldIndex("address"));
    21.  
    22.  
    23. connect(pushButton, SIGNAL(clicked()),
    24. mapper, SLOT(updateButton(int)));
    25.  
    26. setWindowTitle(tr("WiseAviation"));
    27. mapper->toFirst();
    28.  
    29.  
    30. }
    31.  
    32. void MainWindow::setupModel()
    33. {
    34. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    35. db.setHostName("localhost");
    36. db.setDatabaseName("wiseavi");
    37. db.setUserName("root");
    38. db.setPassword("root");
    39. if (!db.open()) {
    40. QMessageBox::critical(0, tr("Cannot open database"),
    41. tr("Unable to establish a database connection.\n"
    42. "This example needs SQMySQL support. Please read "
    43. "the Qt SQL driver documentation for information how "
    44. "to build it."), QMessageBox::Cancel);
    45. return;
    46. }
    47.  
    48. QSqlQuery query;
    49. query.exec("create table workers (name varchar(20), address varchar(200)");
    50. query.exec("insert into workers values( 'Siti', "
    51. "'Sabah')");
    52. query.exec("insert into workers values( 'Atun', "
    53. "'Perak')");
    54. query.exec("insert into workers values( 'fifa', "
    55. "'kedah')");
    56.  
    57.  
    58. model = new QSqlRelationalTableModel(this);
    59. model->setTable("workers");
    60. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    61. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    62. model->select();
    63.  
    64.  
    65.  
    66. }
    67.  
    68. void MainWindow::updateButton(int row)
    69. {
    70. pushButton->update();
    71. }
    To copy to clipboard, switch view to plain text mode 



    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: error...

    This is probably not going to solve your problem, but it's an error nontheless.

    Qt Code:
    1. connect(pushButton, SIGNAL(clicked()), mapper, SLOT(updateButton(int)));
    To copy to clipboard, switch view to plain text mode 
    This is wrong for at least two reasons:
    1. slots can not have more parameters than signals
    2. mapper doesn't contain a slot called updateButton(int)

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error...

    Am not sure where the installEventFilter code is coming from.
    But my guess is mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    this is QMainWindow, and you need to assign a view(QTableView) to the delegate.
    And you havent created a view !!

  6. #6
    Join Date
    May 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error...

    i still don't understand..
    i use textedit to view ..

    could u please to give some code or example to show my data on table?

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 11:05
  2. Replies: 0
    Last Post: 4th November 2009, 10:21
  3. Replies: 1
    Last Post: 25th October 2008, 19:18
  4. qTextEdit error - clipboard error
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 09:21
  5. ERROR:: QPainter: Internal error; no available GC
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 06:05

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.