so, thanks for your answers...
I had pasted the code right into the:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
it is in the .cpp file
I guess, nobody knew about it...
Full code is:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("MyDB");
db.setUserName("root");
db.setPassword("123456789");
if(!db.open())
{
qDebug() << "Error connecting";
}
else
{
qDebug() << "Connected";
QSqlQueryModel *model = new QSqlQueryModel (ui->comboBox);
model->setQuery ("SELECT country_name FROM Country");
ui->comboBox->setModel(model);
}
}
MainWindow::~MainWindow()
{
delete ui;
}