0

I wrote a SQLite database for client server program. but during debug when it comes to line which I star in code it crash and stop debuging. Could you please help me ?thanks

Here is the code:

bool create = !QFile::exists("Message.dat");

if (!myserver.createConnection())
   return 1;

if (create)    ***"Here return false"****

   myserver.insertMessage();

void insertMessage(QString IPAddrress, QDate date, QString message)
{
    QSqlQuery query;
    query.addBindValue(IPAddrress);
    query.addBindValue(date);
    query.addBindValue(message);
    query.exec();
}

void MainWindow::insertMessage()
{
  QSqlQuery query;

  query.prepare("INSERT INTO messages(IPAddress, date, message)"
                        " values(?,?,?)");
 }
1
  • 2
    This question is unanswerable with the code provided... but, it looks like you think the two query objects are somehow the same object (because you prepare it in one function, and bind values in another). They are not, they are two separate objects. Also, try explicitly giving the database to the query, just to be sure it really uses the same database. And check return value of every method, which may return an error. Commented Dec 26, 2015 at 17:43

1 Answer 1

1

Please take a look at this line:

bool create = !QFile::exists("Message.dat");

The way your syntax is written, it says create is true if "Message.dat" does not exist, because you have a ! in front of the exists function. This will return false if "Message.dat" does exist. Try removing the ! operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.