我需要打开Config文件.配置文件位置是exe文件所在的目录.基本上,我怎么能得到这个位置?
我尝试使用QDir,但是当未打开文件时,我的当前代码返回错误.
QString cfg_name = QDir::currentPath() + "config.cfg";
QFile File(cfg_name);
if (File.open(QIODevice::ReadOnly))
{
QTextStream in(&File);
int elementId;
while (!in.atEnd())
{
QString line = in.readLine();
filename[elementId] = line;
elementId++;
}
}
else
{
QMessageBox msgBox;
msgBox.setText("Can't open configuration file!");
msgBox.exec();
}
File.close();
Run Code Online (Sandbox Code Playgroud) 这是我的桌子。id 预计为主键并自动填充
mysql> DESCRIBE test_table
-> ;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(8) | NO | PRI | NULL | |
| name | varchar(256) | YES | | NULL | |
| phone | varchar(20) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
但是,当我以这种方式插入数据时
mysql> INSERT INTO test_table (name, phone) VALUES ('Nikita', '26908050');
Run Code Online (Sandbox Code Playgroud)
它返回错误,该 id 没有默认值。
ERROR 1364 (HY000): Field …Run Code Online (Sandbox Code Playgroud)