Can someone help me figure out what I am doing wrong?
I am trying to pass QSqlQueryModel reference to my List widget so it can add list items. This code below should clear db contents of my table for now as a test because I plan on building QWidgetMapper into List later.
Code & Edit! 8-15 @ 1:50 PST
This is my error: ( Line error numbers do not match below code.)
- ..\DBWidgetMap\trackersql.cpp: In member function 'QSqlQueryModel* TrackerSql::getListModel()':
- ..\DBWidgetMap\trackersql.cpp:38: error: cannot convert 'QSqlQueryModel' to 'QSqlQueryModel*' in return
Here are what the classes do:
MainWindow : Main control class.
TrackerSQL : Sql queries.
List: Widget manages visual representation of ListUI.
ListUI: Visual representation for List. ( Not shown below, no need)
- MainWindow - > (TrackerSql, List = ( ListUI ))
Code: MainWindow
#include <QtGui/QMainWindow>
#include <QLayout>
#include "list.h"
#include "trackersql.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void windowFields(void); // Set the `MainWindow` widget's to be displayed.
void createWindowFields(void); // Create widget fields to be displayed.
void arrangeWindowFields(void); // Arrange the `MainWindow` layout.
List *cardList; // Visual widget for display. Holds a list of cards in database.
TrackerSql *sqlModel; // Access to database queries.
QHBoxLayout *hCard; // Layout container for `MainWindow`.
};
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
QWidget *mainW = new QWidget;
setCentralWidget(mainW);
windowFields();
mainW->setLayout(hCard);
}
MainWindow::~MainWindow(){}
void MainWindow::windowFields(void){
// it works
}
void MainWindow::createWindowFields(void){
sqlModel = new TrackerSql;
cardList = new List(sqlModel->getListModel(), this);
}
void MainWindow::arrangeWindowFields(void){
// it works...
}
Code: TrackerSQL
#include <QWidget>
#include <QtSql>
class TrackerSql : public QWidget
{
Q_OBJECT
public:
explicit TrackerSql(QWidget *parent = 0);
void connectSQL(void); // Start sql connections and initialize `dbQuery`(s).
void setConnection(void); // Set the connection parameters.
void createConnection(void); // Start the `db` connection.
void createTableQuerys(void); // Create `dbQuery`(s).
QSqlQueryModel *getListModel(void);// Pass the refference location to query results
QSqlDatabase db;
QSqlQueryModel dbQueryCard;
QString // connection variables...
};
TrackerSql::TrackerSql(QWidget *parent) :
QWidget(parent)
{
db = QSqlDatabase::addDatabase("QMYSQL");
connectSQL();
}
void TrackerSql::connectSQL(void){
setConnection();
createConnection();
createTableQuerys();
}
void TrackerSql::setConnection(void){
// it works...
}
void TrackerSql::createConnection(void){
// it works...
db.open();
}
void TrackerSql::createTableQuerys(void){
dbQueryCard.setQuery("SELECT * FROM Card");
}
QSqlQueryModel *TrackerSql::getListModel(void){
return dbQueryCard;
}
Code: List
#include "listui.h"
#include <QSqlQueryModel>
#include <QWidgetMapper>
class List : public ListUI {
Q_OBJECT
public:
explicit List(QSqlQueryModel *model, QWidget *parent); // Initialize with model reference location of model.
void setListItems(QSqlQueryModel *model); // Set card list. (currently in debug output mode for test)
};
List::List(QSqlQueryModel *model, QWidget *parent) : ListUI(parent){
setListItems(model);
}
void List::setListItems(QSqlQueryModel *model){
model->clear();
}
Also can I propose a moderator add the tag Qt?