找回密码
 立即注册
收起左侧

关于数据库运行出现:-1: 错误:cannot open output file debug\database

2
回复
8356
查看
[复制链接]
累计签到:1 天
连续签到:1 天
来源: 2017-5-14 21:11:21 显示全部楼层 |阅读模式
2Qter豆
问一下Qt Creator 第二版快速入门中第十七章
P369------P372的上半部分,运行代码出现

:-1: 错误:cannot open output file debug\databaseDriver.exe: Permission denied
:-1: 错误:collect2: ld returned 1 exit status

databaseDriver.pro
SOURCES += \    main.cppQT+=sql
HEADERS += \    connection.h

connection.h

#ifndef CONNECTION_H#define CONNECTION_H#include<QMessageBox>#include<QSqlDatabase>#include<QSqlQuery>
static bool createConnection(){    QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");    db.setDatabaseName(":memory:");    if(! db.open())    {        QMessageBox::critical(0,"Cannot open database","Unable to establish a database connection.",QMessageBox::Cancel);        return false;    }    QSqlQuery query;    query.exec("create table student (id int primary key,""name varchar(20))");    query.exec("insert into student values(0,LiMing)");    query.exec("insert into student values(1,LiuTao)");    query.exec("insert into student values(2,WangHong)");    return true;}
#endif // CONNECTION_H

connection.h
#include<QApplication>#include<QSqlDatabase>#include<QDebug>#include<QStringList>#include"connection.h"#include<QVariant>
int main(int argc,char *argv[]){    QApplication a(argc,argv);    if(!createConnection())return 1;    QSqlQuery query;    query.exec("select * from student");    while(query.next())    {        qDebug()<<query.value(0).toInt()<<query.value(1).toString();    }    return a.exec();}



回复

使用道具 举报

累计签到:127 天
连续签到:1 天
2017-5-14 22:39:24 显示全部楼层
是不是之前运行的没有关掉,图片中应用程序输出中运行的叉掉它

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

累计签到:955 天
连续签到:1 天
2017-5-15 09:13:12 显示全部楼层
程序进程未成功退出,在任务管理器中把你的程序进程手动停止
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了