2

I am running Ubuntu 14.04 (Trusty Tahr). I have installed Qt from the package qt-sdk. I have also installed the following package which should have installed the PostgreSQL driver:

libqt5sql5-psql

My Qt version is:

Qt Creator 3.0.1 based on Qt 5.2.1

When I try to create a Qt db object of type postgres like so:

QSqlDatabase db = QSqlDatabase::addDatabase(“QPSQL”);

I get a lot of errors like so:

/home/bc/projects/qt_test/main.cpp:12: error: stray '\342' in program
     QSqlDatabase db = QSqlDatabase::addDatabase(“QPSQL”);
     ^
/home/bc/projects/qt_test/main.cpp:12: error: 'QPSQL' was not declared in this scope
     QSqlDatabase db = QSqlDatabase::addDatabase(“QPSQL”);

I am obviously not doing something correctly. I don't know what though. Perhaps I am missing a package, or I have misconfigured something.

How can I fix it?

6
  • 2
    I highly doubt this has anything to do with any specific database. It sounds like you copied/pasted code from somewhere and wound up with non-ascii characters in your code. Commented Nov 5, 2014 at 20:54
  • 1
    You are absolutely right. If you look closely- the quotes aren't correct. I copy pasted this from the qt documents. Commented Nov 5, 2014 at 20:57
  • I fixed it and it works now. You did answer my question, so you might as well make this a proper answer so I can select it as an answer and close the issue. Commented Nov 5, 2014 at 20:58
  • Some (crucial) error messages must have been left out. "", at least as posted here, is Unicode code point U+201C (LEFT DOUBLE QUOTATION MARK). The UTF-8 sequence is 0xE2 0x80 0x9C (hexadecimal), 342 200 234 (octal), so "error: stray '\342' in program. error: stray '\200' in program. error: stray '\234' in program" is expected in the error output (three errors for this one character alone). Commented Apr 25, 2023 at 22:04
  • This is a very common error when copying code from web pages, PDF documents, through chat (e.g. Skype Chat or Facebook Messenger), etc. The canonical question is Compilation error: stray ‘\302’ in program, etc.. Commented Apr 25, 2023 at 22:07

2 Answers 2

1

This isn't a database issue: the compiler is telling you that you have non-ASCII characters in your code that it doesn't recognize:

error: stray '\342' in program

Take care of those and you should at least get as far as compiling.

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

Comments

0

Use proper quotes, not the fancy ones from some blogs:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");

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.