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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Stanimirovv
  • 3,064
  • 8
  • 32
  • 56
  • 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. – MrEricSir Nov 05 '14 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. – Stanimirovv Nov 05 '14 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. – Stanimirovv Nov 05 '14 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](https://www.charset.org/utf-8/9)). 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). – Peter Mortensen Apr 25 '23 at 22:04
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 25 '23 at 22:07
  • Regular expression `\x{00A0}|\x{200B}|\x{200C}|\x{FEFF}|\x{2013}|\x{2014}|\x{201C}|\x{201D}|\x{2212}|\x{00E4}|\x{FFFC}|\x{FFFD}|\x{2217}|\x{200C}|\x{202B}|\x{202A}|\x{FF1A}|\x{21B5}` can be used to positively identify (and replace) the most common ones. – Peter Mortensen Apr 25 '23 at 22:10

2 Answers2

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.

MrEricSir
  • 8,044
  • 4
  • 30
  • 35
0

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

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
Simon Warta
  • 10,850
  • 5
  • 40
  • 78