Danke erstmal.
Ich bin dem mal nachgegangen und komme irgendwie noch nicht ganz zum Ziel.
Das mit QTableView konstruierte Fenster klappt kurz auf und ist sofort wieder verschwunden. Geht so schnell, man sieht es kaum.
Hier einmal mein komplettes Grundgerüst:
main.cpp
Code: Alles auswählen
#include <QApplication>
#include "QMeinHauptFenster.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMeinHauptFenster *window = new QMeinHauptFenster;
window->show();
return app.exec();
}
---
QMeinHauptFenster.h
Code: Alles auswählen
#include "ui_meineui.h"
class QMeinHauptFenster : public QMainWindow, private Ui::HauptFenster
{
Q_OBJECT
public:
QMeinHauptFenster(QWidget *parent = 0);
QString myQuery;
public slots:
void queryAusfuehren();
};
---
QMeinHauptFenster.cpp
Code: Alles auswählen
#include "QMeinHauptFenster.h"
#include <QTextEdit>
#include <QMessageBox>
#include <QtSql>
#include <QtGui/QtGui>
#include <QTableWidgetItem>
#include <QTableWidget>
#include <vector>
QMeinHauptFenster::QMeinHauptFenster(QWidget *parent) : QMainWindow(parent)
{
setupUi(this);
myQuery = "";
memoQueryText->setPlainText("SELECT * FROM test");
// SgQueryErgebnis->setRowCount(10);
// SgQueryErgebnis->setColumnCount(15);
QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(queryAusfuehren()));
};
void QMeinHauptFenster::queryAusfuehren()
{
myQuery= memoQueryText->toPlainText();
QSqlDatabase defaultDB = QSqlDatabase::addDatabase("QSQLITE");
defaultDB.setDatabaseName("mydb.db");
if ( defaultDB.open() )
{
QMessageBox::about(this, "Query",myQuery);
QSqlQuery target;
QSqlQuery query( myQuery, defaultDB );
QSqlQueryModel model;
model.setQuery("select * from test");
QTableView view;
view.setModel(&model);
view.show();
}
}
Nicht wundern, die Includes kommen teilweise noch von früheren vergeblichen Versuchen.
ui_meineui.h
Code: Alles auswählen
#ifndef UI_MEINEUI_H
#define UI_MEINEUI_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QTableWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QWidget>
class Ui_HauptFenster
{
public:
QWidget *centralWidget;
QPushButton *pushButton;
QLineEdit *lineEdit;
QTableWidget *SgQueryErgebnis;
QTextEdit *memoQueryText;
void setupUi(QMainWindow *HauptFenster)
{
HauptFenster->setObjectName(QString::fromUtf8("HauptFenster"));
HauptFenster->resize(QSize(735, 472).expandedTo(HauptFenster->minimumSizeHint()));
centralWidget = new QWidget(HauptFenster);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(300, 170, 101, 31));
lineEdit = new QLineEdit(centralWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(40, 180, 171, 20));
SgQueryErgebnis = new QTableWidget(centralWidget);
SgQueryErgebnis->setObjectName(QString::fromUtf8("SgQueryErgebnis"));
SgQueryErgebnis->setGeometry(QRect(40, 220, 651, 221));
memoQueryText = new QTextEdit(centralWidget);
memoQueryText->setObjectName(QString::fromUtf8("memoQueryText"));
memoQueryText->setGeometry(QRect(43, 30, 651, 121));
HauptFenster->setCentralWidget(centralWidget);
retranslateUi(HauptFenster);
QMetaObject::connectSlotsByName(HauptFenster);
} // setupUi
void retranslateUi(QMainWindow *HauptFenster)
{
HauptFenster->setWindowTitle(QApplication::translate("HauptFenster", "MainWindow"));
pushButton->setText(QApplication::translate("HauptFenster", "PushButton"));
memoQueryText->setHtml(QApplication::translate("HauptFenster", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:Sans Serif; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">TEST</p></body></html>"));
Q_UNUSED(HauptFenster);
} // retranslateUi
};
namespace Ui {
class HauptFenster: public Ui_HauptFenster {};
} // namespace Ui
#endif // UI_MEINEUI_H
Wie binde ich das TableView-Object in mein Formular ein?
Und wie erreiche ich, dass es etwas länger angezeigt wird ?
Ein Anzeigen der Datensätze in ein QTableWidget ist also nicht so ohne weiteres möglich?
Gruß, gosar.