@cristian-adam As I reported earlier, I believed the problem had to do with the code that uses sqlite3_create_function to create a sqlit3 function which means that my cpp file needs to include "sqlite3.h". Furthermore, this file needs to be the same as that used in the particular Qt version.
Here is my code to do this:
void distanceFunc(sqlite3_context* ctx, int argc, sqlite3_value **argv)
{
double Lat1, Lon1, Lat2, Lon2;
Lat1 = sqlite3_value_double(argv[0]);
Lon1 = sqlite3_value_double(argv[1]);
Lat2 = sqlite3_value_double(argv[2]);
Lon2 = sqlite3_value_double(argv[3]);
// sqlite3_result_value(distance(LatLng(a1,a2),LatLng(a3,a4)));
if (Lat1 == Lat2 && Lon1 == Lon2)
sqlite3_result_double(ctx,0);
double R = 6371; // RADIUS OF THE EARTH IN KM
double dToRad = 0.0174532925;
double lat1 = Lat1 * dToRad;
//double lon1 = Lon1 * dToRad;
double lat2 = Lat2 * dToRad;
//double lon2 = Lon2 * dToRad;
double dLat = dToRad * (Lat2 - Lat1);
double dLon = dToRad * (Lon2 - Lon1);
double a = qSin(dLat / 2) * qSin(dLat / 2)
+ qCos(lat1) * qCos(lat2)
* qSin(dLon / 2) * qSin(dLon / 2);
double c = 2 * qAtan2(qSqrt(a), qSqrt(1 - a));
double d = R * c;
sqlite3_result_double(ctx,d); // distance in kilometers
}
bool SQL::loadSqlite3Functions(QSqlDatabase db)
{
QVariant v = db.driver()->handle();
sqlite3 *db_handle = NULL;
if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0)
{
// v.data() returns a pointer to the handle
db_handle = *static_cast<sqlite3 **>(v.data());
if (!db_handle) {
qCritical() <<"Cannot get a sqlite3 handler.";
return false;
}
sqlite3_initialize();
if(sqlite3_create_function(db_handle, "distance", 4, SQLITE_ANY, 0, &distanceFunc, 0, 0))
{
qCritical() << "Cannot create SQLite functions: sqlite3_create_function failed.";
return false;
}
return true;
}
qCritical() << "Cannot get a sqlite3 handle to the driver.";
return false;
}
code_text
including this file, sqlite3.pri in my .pro file appears to have solved my problem as the compiled program now runs in release mode as well as debug mode!
SOURCES += $$(QTDIR)/../Src/qtbase/src/3rdparty/sqlite/sqlite3.c
HEADERS += $$(QTDIR)/../Src/qtbase/src/3rdparty/sqlite/sqlite3.h
win32:QMAKE_POST_LINK += $$QMAKE_COPY $$shell_quote( $$(QTDIR)\\..\\Src\\qtbase\\src\\3rdparty\\sqlite\\sqlite3.h) $$shell_path($$PWD) $$escape_expand(\\n\\t)
else:unix:QMAKE_POST_LINK += $$QMAKE_COPY $$shell_quote( $$(QTDIR)/../Src/qtbase/src/3rdparty/sqlite/sqlite3.h) $$shell_quote($$PWD) $$escape_expand(\\n\\t)
message($$QMAKE_POST_LINK)
``
Now, to insure that the MacOS version has no problem with the change.