Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database windows中与qt creator的postgresql连接错误_Database_Qt_Postgresql_Connection - Fatal编程技术网

Database windows中与qt creator的postgresql连接错误

Database windows中与qt creator的postgresql连接错误,database,qt,postgresql,connection,Database,Qt,Postgresql,Connection,我的qui上有一个按钮。当我点击它时,根据连接信息,它必须是connectdatabase 这是我的密码: void MainWindow::on_pushButton_clicked(){ db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("localhost"); db.setDatabaseName("Assignment3"); db.setUserName("postgres"); d

我的qui上有一个按钮。当我点击它时,根据连接信息,它必须是connectdatabase

这是我的密码:

void MainWindow::on_pushButton_clicked(){
    db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("Assignment3");
    db.setUserName("postgres");
    db.setPassword("password");
    db.setPort(5432);

    bool ok = db.open();
    if(ok != true)
    {
        QMessageBox::information(this,"Connection","Connection Failed!") ;
    }
    else
    {
        QMessageBox::information(this,"Connection","Connection OK!") ;

        QSqlQueryModel model;
        model.setQuery("select * from students ");

        //ui->tableView->setModel(&model);
        QMessageBox::information(this,"Information","This Message box is needed in       order to see the rendered tableview!") ;

    }
}

主机名、数据库名、用户名、密码和端口正确,postgresql中的我的数据库处于活动状态,其中不包含表


感谢您的帮助。提前感谢。

如果您错过了驾驶员(如评论所示),那么您应该考虑获得它

例如,在Debian上,您可以:

apt-get install  libqt4-sql-psql
在Fedora上,您将使用类似的yum命令


但是,在不了解您的平台的情况下,我无法建议具体步骤。

消息框中会说什么?“连接失败”。问题是qt没有qpsql驱动程序。您的.pro文件中是否有
win32:LIBS+=libpqdll.lib
?您有使用postgresql支持构建的Qt吗?请尝试
db.lastError().text()有关更多信息QSQLDABASE:QPSQL驱动程序未加载QSQLDABASE:可用驱动程序:QSQLITE QODBC QODBC3