Domanda

I made a setup packadge of some program in Visual Studio 2008. So on my PC after installation everything works well. On others PC when you just click on database connection option it just crashes.

Well, here's the error

enter image description here

I think it appears at this line

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

in database initialization part because of message about DB apperas and everything seems work fine until this line.

Here's full function

void DatabaseManagement::initDatabase(){
    QMessageBox::information(this, "error tracking step 5", " DB ADDED");

    database = QSqlDatabase::addDatabase("QPSQL");
    
    QStringList sdrivers = QSqlDatabase::drivers();
    //output all avalible drivers
    QString driver = sdrivers[0];
    for(int i = 0; i< sdrivers.size();i++)
        QMessageBox::information(this, "Driver info", sdrivers[i]);

    
}

database variable here is global for DatabaseManagement class. Also in this class I got getDatabase function which returns database variable and I use it in other class, let say in mainClass (in case if this could be cause of the problem).

What coulbe be the cause of this problem? How could I solve that? By the way, I use Qt 4.7.4

UPD: Well, the problem solved! I forget to add sqldrivers folder! Of course I added all necessary .dlls but for some reason program see it only in this folder. Hope it could be helpful for somebody. By the way DependencyWalker show taht nothing was wrong with not working version (without sqldrivers folder).

È stato utile?

Soluzione

My guess would be that the problem lies here (A debugger would tell you more):

QStringList sdrivers = QSqlDatabase::drivers();
//output all available drivers
QString driver = sdrivers[0];

You're accessing sdrivers[0] without checking that sdrivers contains at least one element. I assume you didn't deploy the Qt SQL plugins correctly and thus none is found on the other computer. So fix above code (guarding it with if (!sdrivers.isEmpty())) and deploy the plugins.

Altri suggerimenti

The problem is more likely this line: QString driver = sdrivers[0]; I guess you forgot to provide the sql-plugin folder? %YOUR-APP-PATH%/plugins/qpsql.dll

Try adding:

if(sdrivers.size() > 0)
    QString driver = sdrivers[0];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top