PDA

View Full Version : error...



kazal
30th June 2010, 09:55
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?

aamer4yu
30th June 2010, 10:06
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

kazal
30th June 2010, 10:15
well i dont understand what it means..huhuh

now i try write database using progrmmg..

this my mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QWidget>

class QComboBox;
class QDataWidgetMapper;
class QItemSelectionModel;
class QLabel;
class QLineEdit;
class QPushButton;
class QSqlRelationalTableModel;
class QStandardItemModel;
class QStringListModel;
class QTextEdit;

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);

private slots:
void updateButton(int row);

private:
void setupModel();

QLabel *label;
QTextEdit *textEdit;
QComboBox *comboBox;
QPushButton *pushButton;

QSqlRelationalTableModel *model;
QItemSelectionModel *selectionModel;
QDataWidgetMapper *mapper;



};

#endif // MAINWINDOW_H





mainwindow.cpp



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlTableModel>
#include <QDataWidgetMapper>
#include <QSqlRelationalDelegate>
#include <QSqlRelationalTableModel>
#include <QMessageBox>
#include <QSqlQuery>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)

{
setupModel();

mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(comboBox, model->fieldIndex("name"));
mapper->addMapping(textEdit, model->fieldIndex("address"));


connect(pushButton, SIGNAL(clicked()),
mapper, SLOT(updateButton(int)));

setWindowTitle(tr("WiseAviation"));
mapper->toFirst();


}

void MainWindow::setupModel()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("wiseavi");
db.setUserName("root");
db.setPassword("root");
if (!db.open()) {
QMessageBox::critical(0, tr("Cannot open database"),
tr("Unable to establish a database connection.\n"
"This example needs SQMySQL support. Please read "
"the Qt SQL driver documentation for information how "
"to build it."), QMessageBox::Cancel);
return;
}

QSqlQuery query;
query.exec("create table workers (name varchar(20), address varchar(200)");
query.exec("insert into workers values( 'Siti', "
"'Sabah')");
query.exec("insert into workers values( 'Atun', "
"'Perak')");
query.exec("insert into workers values( 'fifa', "
"'kedah')");


model = new QSqlRelationalTableModel(this);
model->setTable("workers");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();



}

void MainWindow::updateButton(int row)
{
pushButton->update();
}




main.cpp


#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

tbscope
30th June 2010, 10:53
This is probably not going to solve your problem, but it's an error nontheless.



connect(pushButton, SIGNAL(clicked()), mapper, SLOT(updateButton(int)));

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)

aamer4yu
30th June 2010, 11:07
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 !!

kazal
30th June 2010, 11:25
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?