PDA

View Full Version : primary expression before '.'



rahulvishwakarma
15th March 2020, 11:21
hi to all, I've centos 7.5 as client and centos 6.10 as mysql server in VM. I am trying to compile a simple program to login in MySQL server as follows :-


void MyMainWindow::on_pushButtonLogin_clicked()
{
QString user = ui->lineEditUserName->text().trimmed();
QString passwd = ui->lineEditPassword->text().trimmed();

db = connDB.connectDB(db, &user, &passwd);// <- here is problem

if(db->open())
{
QMessageBox::information(this, "Login", " Connection Succeeded");
}
else
{
QMessageBox::warning(this, "Login", "Coneection failure : " +db->lastError().text());
}
}

here connDB is class and having a static member function connectDB(QSqldatabase *db, QString *user, QString *passwd).
error is :-


mymainwindow.cpp:34: error: expected primary-expression before '.' token
in db = connDB.connectDB(db, &user, &passwd);

code for connectDB :-


QSqlDatabase * connDB::connectDB(QSqlDatabase *db, QString *uname, QString *passwd )
{
db->setDatabaseName("cbs");
db->setHostName("serverora11gr2.db.net");
db->setUserName(*uname);
db->setPassword(*passwd);
db->setPort(3306);
return db;
}


how to resolve this error.

Lesiok
15th March 2020, 16:37
db = connDB::connectDB(db, &user, &passwd);
Read about the basics of C++.

rahulvishwakarma
16th March 2020, 09:38
thanks a lot , you solved my problem.