异度部落格

学习是一种生活态度。

0%

thunderbird邮件提醒设置 如果你使用 Ubuntu 9.04,给 ThunderBird 安装Mozilla Notification Extensions就可以让它使用 LibNotify 新通知系统 下载地址:https://addons.mozilla.org/en-US/thunderbird/addon/11530

thunderbird最小化到托盘 由于 thunderbird 没有最小化到托盘的扩展,这里用Alltray来模拟: sudo apt-get install alltray

新建文件,thunderbirdStart.sh 内容如下:

#!/bin/bash
alltray thunderbird

保存退出,并使文件可执行

打开System->Preferences->Sessions 添加此文件使之开机时运行

同样的方法也可以添加其他程序

添加联系人侧边栏 安装Contacts Sidebar插件就可以了 下载地址:https://addons.mozilla.org/en-US/thunderbird/addon/70

方法一:添加命令到rc.local

方法二:系统->首选项->启动程序(会话)

Ubuntu 运行程序不用密码的方法,其实就是修改权限

sudo chmod 4577 XXX

显然 include 是没错的,可是怎么也找不到这个文件,程序编译不过.....

解决方案如下:

在 XXX.pro 文件中添加一行

QT += sql

就可以了,这个方法还可以用再其他场合...要是找不到什么头文件可以考虑试试

这里利用 Qt4+MySQL 做一个简单的例子

不会连接 MySQL 的,参考这里:http://blog.csdn.net/killua_hzl/archive/2009/07/29/4391956.aspx

代码如下:

studentmanage.h

#ifndef STUDENTMANAGE_H
#define STUDENTMANAGE_H
#include <QtGui/QWidget>
class QSqlTableModel;
class QTableView;
enum { Stu_Sno = 0,Stu_Name = 1,Stu_Age = 2,Stu_Math = 3,Stu_Chinese = 4,Stu_English = 5 };
class StudentManage : public QWidget
{
Q_OBJECT
public:
StudentManage(QWidget *parent = 0);
~StudentManage();
private:
QSqlTableModel *model;
QTableView *view;
};
#endif // STUDENTMANAGE_H

studentmanage.cpp

#include <QtGui>
#include <QtSql>
#include "studentmanage.h"
StudentManage::StudentManage(QWidget *parent)
: QWidget(parent)
{
model = new QSqlTableModel(this);
model->setTable("student");
model->setSort(Stu_Sno, Qt::AscendingOrder);
model->setHeaderData(Stu_Name, Qt::Horizontal, tr("Name"));
model->setHeaderData(Stu_Age, Qt::Horizontal, tr("Age"));
model->setHeaderData(Stu_Math, Qt::Horizontal, tr("Math"));
model->setHeaderData(Stu_Chinese, Qt::Horizontal, tr("Chinese"));
model->setHeaderData(Stu_English, Qt::Horizontal, tr("English"));
model->select();
view = new QTableView;
view->setModel(model);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->resizeColumnsToContents();
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
QHeaderView *headerView = view->horizontalHeader();
headerView->setStretchLastSection(true);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(view);
setLayout(layout);
setWindowTitle(tr("Student Manage"));
}
StudentManage::~StudentManage()
{
}

main.cpp

#include <QtGui/QApplication>
#include <QtSql>
#include <QMessageBox>
#include "studentmanage.h"
/**
建立数据库链接
*/
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("DB_Stu");
db.setUserName("root");
db.setPassword("123456");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
/**
创建数据
*/
void createData()
{
QSqlQuery query;
query.exec("Drop table student"); //如果表存在删除
//建表
query.exec("Create table student ("
"Sno int not null,"
"Name varchar(40) not null,"
"Age int not null,"
"Math int not null,"
"Chinese int not null,"
"English int not null)");
//插入数据
query.exec("Insert into student (Sno,Name,Age,Math,Chinese,English) values(1,'Dear_fox',1,100,100,100)");
query.exec("Insert into student (Sno,Name,Age,Math,Chinese,English) values(2,'Killua',2,99,98,98)");
}
/**
主函数
*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bool isCreate = !QFile::exists("DB_Stu");
if (!createConnection())
return 1;
if(isCreate)
createData();
StudentManage studentManage;
studentManage.resize(400,300);
studentManage.show();
return a.exec();
}

结果截图: ed4fa4671bc2ab0697d9b2d1680f92d8.png

貌似好久没写了,最近比较忙的说,这个主要练习 Model 的设计,部分代码是参考别人的,大牛们不要鄙视啊....

源码最后附上。

部分核心代码如下:

booleanmodel.h

#ifndef BOOLEANMODEL_H
#define BOOLEANMODEL_H
#include <QAbstractItemModel>
class Node;
class BooleanModel : public QAbstractItemModel
{
Q_OBJECT
public:
BooleanModel(QObject *parent = 0);
~BooleanModel();
void setRootNode(Node *node);
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section,Qt::Orientation orientation, int role) const;
private:
Node *nodeFromIndex(const QModelIndex &index) const;
Node *rootNode;
};
#endif // BOOLEANMODEL_H

booleanmodel.cpp

#include <QtCore>
#include "booleanmodel.h"
#include "booleanparser.h"
/**
构造函数,初始化根结点为空
*/
BooleanModel::BooleanModel(QObject *parent) :QAbstractItemModel(parent)
{
rootNode = 0;
}
/**
析构函数,删除根结点
*/
BooleanModel::~BooleanModel()
{
delete rootNode;
}
/**
设置根结点,删除原来根结点,重新设置根结点
*/
void BooleanModel::setRootNode(Node *node)
{
delete rootNode;
rootNode = node;
reset(); //刷新表格数据
}
/**
返回索引,这个是virtual函数所以一定要重载
*/
QModelIndex BooleanModel::index(int row,int column,const QModelIndex &parent) const
{
if (!rootNode || row < 0 || column < 0)
return QModelIndex(); //非法情况
Node *parentNode = nodeFromIndex(parent);
Node *childNode = parentNode->children.value(row);
if (!childNode)
return QModelIndex();
return createIndex(row,column, childNode);
}
/**
返回父亲结点
*/
QModelIndex BooleanModel::parent(const QModelIndex &child) const
{
Node *node = nodeFromIndex(child);
if (!node)
return QModelIndex(); //结点无效
Node *parentNode = node->parent;
if (!parentNode)
return QModelIndex(); //父结点无效
Node *grandparentNode = parentNode->parent;
if(!grandparentNode)
return QModelIndex(); //父结点的父结点无效
int row = grandparentNode->children.indexOf(parentNode);
return createIndex(row,0,parentNode);
}
/**
返回行数,这个也是virtual函数,要重载
*/
int BooleanModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0)
return 0;
Node *parentNode = nodeFromIndex(parent);
if(!parentNode)
return 0;
return parentNode->children.count();
}
/**
返回列数,固定只有2,这个也是virtual函数,要重载
*/
int BooleanModel::columnCount(const QModelIndex & /*parent*/) const
{
return 2;
}
/**
返回数据,这个也是virtual函数,要重载
*/
QVariant BooleanModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
return QVariant(); //不是显示角色,认为是无效数据
Node *node = nodeFromIndex(index);
if (!node)
return QVariant(); //结点无效
if(index.column() == 0) {
switch (node->type) {
case Node::Root:
return tr("Root");
case Node::OrExpression:
return tr("OR Expression");
case Node::AndExpression:
return tr("AND Expression");
case Node::NotExpression:
return tr("NOT Expression");
case Node::Atom:
return tr("Atom");
case Node::Identifier:
return tr("Identifier");
case Node::Operator:
return tr("Operator");
case Node::Punctuator:
return tr("Punctuator");
default:
return tr("Unknown"); //默认为未知
}
} else if(index.column() == 1) {
return node->str;
}
return QVariant();
}
/**
返回表头
*/
QVariant BooleanModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (section == 0) {
return tr("Node");
} else if (section == 1) {
return tr("Value");
}
}
return QVariant();
}
/**
从索引返回结点
*/
Node *BooleanModel::nodeFromIndex(const QModelIndex &index) const
{
if (index.isValid()) {
return static_cast<Node *>(index.internalPointer());
} else {
return rootNode;
}
}

booleanparser.h

#ifndef BOOLEANPARSER_H
#define BOOLEANPARSER_H
#include "node.h"
class BooleanParser
{
public:
BooleanParser();
Node *parse(const QString &expr);
private:
Node *parseOrExpression();
Node *parseAndExpression();
Node *parseNotExpression();
Node *parseAtom();
Node *parseIdentifier();
void addChild(Node *parent, Node *child);
void addToken(Node *parent, const QString &str, Node::Type type);
bool matchToken(const QString &str) const;
QString in;
int pos;
};
#endif // BOOLEANPARSER_H

booleanparser.cpp

#include <QtCore>
#include "booleanparser.h"
#include "node.h"
BooleanParser::BooleanParser()
{
}
Node *BooleanParser::parse(const QString &expr)
{
in = expr;
in.replace(" ", "");
pos = 0;
Node *node = new Node(Node::Root);
addChild(node, parseOrExpression());
return node;
}
/**
解析或表达式
*/
Node *BooleanParser::parseOrExpression()
{
Node *childNode = parseAndExpression();
if (matchToken("||")) {
Node *node = new Node(Node::OrExpression);
addChild(node,childNode);
while (matchToken("||")) {
addToken(node,"||", Node::Operator);
addChild(node, parseAndExpression());
}
return node;
} else {
return childNode;
}
}
/**
解析与表达式
*/
Node *BooleanParser::parseAndExpression()
{
Node *childNode = parseNotExpression();
if (matchToken("&&")) {
Node *node = new Node(Node::AndExpression);
addChild(node, childNode);
while (matchToken("&&")) {
addToken(node, "&&", Node::Operator);
addChild(node, parseNotExpression());
}
return node;
} else {
return childNode;
}
}
/**
解析非表达式
*/
Node *BooleanParser::parseNotExpression()
{
if (matchToken("!")) {
Node *node = new Node(Node::NotExpression);
while (matchToken("!"))
addToken(node, "!", Node::Operator);
addChild(node, parseAtom());
return node;
} else {
return parseAtom();
}
}
/**
解析一个项
*/
Node *BooleanParser::parseAtom()
{
if (matchToken("(")) {
Node *node = new Node(Node::Atom);
addToken(node, "(", Node::Punctuator);
addChild(node, parseOrExpression());
addToken(node, ")", Node::Punctuator);
return node;
} else {
return parseIdentifier();
}
}
/**
解析标识符
*/
Node *BooleanParser::parseIdentifier()
{
int startPos = pos;
while (pos < in.length() && in[pos].isLetterOrNumber())
++pos;
if (pos > startPos) {
return new Node(Node::Identifier,
in.mid(startPos, pos - startPos));
} else {
return 0;
}
}
/**
添加子结点
*/
void BooleanParser::addChild(Node *parent, Node *child)
{
if (child) {
parent->children += child;
parent->str += child->str;
child->parent = parent;
}
}
/**
添加token
*/
void BooleanParser::addToken(Node *parent, const QString &str,
Node::Type type)
{
if (in.mid(pos, str.length()) == str) {
addChild(parent, new Node(type, str));
pos += str.length();
}
}
/**
token匹配
*/
bool BooleanParser::matchToken(const QString &str) const
{
return in.mid(pos, str.length()) == str;
}

booleanwindow.h

#ifndef BOOLEANWINDOW_H
#define BOOLEANWINDOW_H
#include <QWidget>
class QLabel;
class QLineEdit;
class QTreeView;
class BooleanModel;
class BooleanWindow : public QWidget
{
Q_OBJECT
public:
BooleanWindow();
private slots:private slots:
void booleanExpressionChanged(const QString &expr);
private:
QLabel *label;
QLineEdit *lineEdit;
BooleanModel *booleanModel;
QTreeView *treeView;
};
#endif // BOOLEANWINDOW_H

booleanwindow.cpp

#include <QtGui>
#include "booleanwindow.h"
#include "booleanmodel.h"
#include "booleanparser.h"
BooleanWindow::BooleanWindow()
{
//Label
label = new QLabel(tr("Boolean expression:"));
//LineEdit
lineEdit = new QLineEdit;
//BooleanModel
booleanModel = new BooleanModel(this);
//TreeView
treeView = new QTreeView;
treeView->setModel(booleanModel);
//signal and slot
connect(lineEdit, SIGNAL(textChanged(QString)), this,SLOT(booleanExpressionChanged(QString)));
//Layout
QGridLayout *layout = new QGridLayout;
layout->addWidget(label, 0 ,0);
layout->addWidget(lineEdit, 0 , 1);
layout->addWidget(treeView, 1, 0, 1, 2);
setLayout(layout);
setWindowTitle(tr("Boolean Parser"));
}
void BooleanWindow::booleanExpressionChanged(const QString &expr)
{
BooleanParser parser;
Node *rootNode = parser.parse(expr);
booleanModel->setRootNode(rootNode);
}

其他的可以去下载

下载地址:http://download.csdn.net/source/1529790">http://download.csdn.net/source/1529790

软件截图:

image

PS:最近比较郁闷.....

这个软件用于计算文件夹中图片所占空间大小

程序很短,直接看代码吧

main.cpp

#include <QtGui>
#include <iostream>
#include <string>
/**
计算文件中图片所占大小
*/
qlonglong imageSpaceCompute(const QString &path)
{
QDir dir(path);
qlonglong size = 0;
QStringList filters;
foreach(QByteArray format,QImageReader::supportedImageFormats())
filters += "*." + format;
foreach(QString file, dir.entryList(filters,QDir::Files)) //entryList 返回文件夹下满足条件的文件名列表
size += QFileInfo(dir,file).size();
//递归,计算子目录中的图片大小
foreach (QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
size += imageSpaceCompute(path + QDir::separator() + subDir);
return size;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString path = QDir::currentPath();
std::cout << "Space used by imaged in" << qPrintable(path)
<< " and its subdirectories is " << (imageSpaceCompute(path) / 1024) << " KB" << std::endl;
return 0;
}

要是不能运行看看项目配置文件,这里附上我的

QT       = core gui xml
TARGET = ImageSpaceCompute
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app

SOURCES += main.cpp

软件截图:

image

最近学习 Qt4 的数据库编程方面,早上安装了下 MySQL,这里写 Qt4 连接 MySQL 的方法

首先,自己先去建立一个数据库名为,DB_Name

然后,自己可以尝试下连接,利用 mysql-admin 是个很好用的工具,保证数据连接是没有问题的,这里用的 Server Name 就用本地的吧(localhost)

保证数据库连接没问题以后,就可以参考下这下面的代码了(仅供参考,有问题请来信),我把它写成函数的形式,方便以后调用

bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("DB_Name");
db.setUserName("root");
db.setPassword("123456");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}

Sever Name:localhost 使用本地连接

数据库名:DB_Name

登录账户:root

密码:123456

最近太忙了,都没怎么看 Qt 鄙视下自己....

不说了,放代码

symbolpicker.h

#ifndef SYMBOLPICKER_H
#define SYMBOLPICKER_H
#include <QtGui/QDialog>
#include <QMap>
class QDialogButtonBox;
class QIcon;
class QListWidget;
namespace Ui
{
class SymbolPicker;
}
class SymbolPicker : public QDialog
{
Q_OBJECT
public:
SymbolPicker(const QMap<int,QString> &symbolMap,QWidget *parent = 0);
~SymbolPicker();
int selected() const {return id;}
void done(int result);
private:
Ui::SymbolPicker *ui;
QIcon iconForSymbol(const QString &symbolName);
QListWidget *listWidget;
QDialogButtonBox *buttonBox;
int id;
};
#endif // SYMBOLPICKER_H

symbolpicker.cpp

#include<QtGui>
#include "symbolpicker.h"
#include "ui_symbolpicker.h"
SymbolPicker::SymbolPicker(const QMap<int,QString> &symbolMap,QWidget *parent)
: QDialog(parent), ui(new Ui::SymbolPicker)
{
ui->setupUi(this);
id = -1; //设置id默认值
listWidget = new QListWidget;
listWidget->setIconSize(QSize(60,60));
QMapIterator<int,QString> i(symbolMap);
while(i.hasNext()) {
i.next();
QListWidgetItem *item = new QListWidgetItem(i.value(),listWidget);
item->setIcon(iconForSymbol(i.value()));
item->setData(Qt::UserRole,i.key());
}
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
connect(buttonBox,SIGNAL(rejected()),this,SLOT(reject()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(listWidget);
layout->addWidget(buttonBox);
setLayout(layout);
setWindowTitle(tr("Symbol Picker"));
}
SymbolPicker::~SymbolPicker()
{
delete ui;
}
void SymbolPicker::done(int result)
{
id = -1;
if (result == QDialog::Accepted) {
QListWidgetItem *item = listWidget->currentItem();
if (item)
id = item->data(Qt::UserRole).toInt();
}
QDialog::done(result);
}
QIcon SymbolPicker::iconForSymbol(const QString &symbolName)
{
QString fileName = ":/images/" + symbolName.toLower();
fileName.replace(' ','-');
return QIcon(fileName);
}

symbolpicker.qrc (资源文件)

<RCC>
<qresource>
<file>images/killua.png</file>
</qresource>
</RCC>

刚开始 icon 显示一直有问题,后来配置了下资源文件就 OK 了...

这个还是练习项视图,用于浏览目录,可以添加新文件夹和删除文件或文件夹

directoryviewer.h

#ifndef DIRECTORYVIEWER_H
#define DIRECTORYVIEWER_H
#include <QtGui/QDialog>
class QDialogButtonBox;
class QDirModel;
class QTreeView;
namespace Ui
{
class DirectoryViewer;
}
class DirectoryViewer : public QDialog
{
Q_OBJECT
public:
DirectoryViewer(QWidget *parent = 0);
~DirectoryViewer();
private slots:
void createDirectory();
void remove();
private:
Ui::DirectoryViewer *ui;
QTreeView *treeView;
QDirModel *model;
QDialogButtonBox *buttonBox;
};
#endif // DIRECTORYVIEWER_H

directoryviewer.cpp

#include <QtGui>
#include "directoryviewer.h"
#include "ui_directoryviewer.h"
/**
构造函数
*/
DirectoryViewer::DirectoryViewer(QWidget *parent)
: QDialog(parent), ui(new Ui::DirectoryViewer)
{
ui->setupUi(this);
//model
model = new QDirModel;
model->setReadOnly(false);
model->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);
//treeView
treeView = new QTreeView;
treeView->setModel(model);
treeView->header()->setStretchLastSection(true);
treeView->header()->setSortIndicator(0,Qt::AscendingOrder);
treeView->header()->setSortIndicatorShown(true);
treeView->header()->setClickable(true);
QModelIndex index = model->index(QDir::currentPath());
treeView->expand(index);
treeView->scrollTo(index);
treeView->resizeColumnToContents(0);
//ButtonBox
buttonBox = new QDialogButtonBox(Qt::Horizontal);
QPushButton *mkdirButton = buttonBox->addButton(tr("&Create Directory"),QDialogButtonBox::ActionRole);
QPushButton *removeButton = buttonBox->addButton(tr("&Remove"),QDialogButtonBox::ActionRole);
buttonBox->addButton(tr("&Quit"),QDialogButtonBox::AcceptRole);

//signal and slot
connect(mkdirButton,SIGNAL(clicked()),this,SLOT(createDirectory()));
connect(removeButton,SIGNAL(clicked()),this,SLOT(remove()));
connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
//Layout
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(treeView);
layout->addWidget(buttonBox);
setLayout(layout);
setWindowTitle(tr("Directory Viewer by Killua"));
}
/**
析构函数
*/
DirectoryViewer::~DirectoryViewer()
{
delete ui;
}
/**
文件夹创建
*/
void DirectoryViewer::createDirectory()
{
QModelIndex index = treeView->currentIndex();
if (!index.isValid())
return ;
QString dirName = QInputDialog::getText(this,tr("Create Directory"),tr("Directory Name"));
if (!dirName.isEmpty()) {
if (!model->mkdir(index,dirName).isValid())
QMessageBox::information(this,tr("Create Directory"),tr("Failed to create"));
}
}
/**
删除
*/
void DirectoryViewer::remove()
{
QModelIndex index =treeView->currentIndex();
if (!index.isValid())
return ;
bool ok;
if (model->fileInfo(index).isDir()) {
ok = model->rmdir(index);
} else {
ok = model->remove(index);
}
if (!ok)
QMessageBox::information(this,tr("Remove"),tr("Failed to remvoe"));
}

软件截图: image

这个主要练习项视图的显示并设置了 insert 和 delete 功能


listviewer.h

#ifndef LISTVIEWER_H
#define LISTVIEWER_H
#include <QtGui/QDialog>
class QDialogButtonBox;
class QListView;
class QStringListModel;
namespace Ui
{
class ListViewer;
}
class ListViewer : public QDialog
{
Q_OBJECT
public:
ListViewer(const QStringList &itemList,QWidget *parent = 0);
~ListViewer();
QStringList itemList() const;
private slots:
void insert();
void del();
private:
Ui::ListViewer *ui;
QListView *listView;
QDialogButtonBox *buttonBox;
QStringListModel *model;
};
#endif // LISTVIEWER_H

listviewer.cpp

#include <QtGui>
#include "listviewer.h"
#include "ui_listviewer.h"
ListViewer::ListViewer(const QStringList &itemList,QWidget *parent)
: QDialog(parent), ui(new Ui::ListViewer)
{
ui->setupUi(this);
//model
model = new QStringListModel(this);
model->setStringList(itemList);
//listView
listView = new QListView;
listView->setModel(model);
listView->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked); //The QAbstractItemView class provides the basic functionality for item view classes.
//buttonBox
buttonBox = new QDialogButtonBox();
QPushButton *insertButton = buttonBox->addButton(tr("&Insert"),QDialogButtonBox::ActionRole); //ActionRole:Clicking the button causes changes to the elements within the dialog
QPushButton *deleteButton = buttonBox->addButton(tr("&Delete"),QDialogButtonBox::ActionRole);
buttonBox->addButton(QDialogButtonBox::Ok);
buttonBox->addButton(QDialogButtonBox::Cancel);
//signals and slots
connect(insertButton,SIGNAL(clicked()),this,SLOT(insert()));
connect(deleteButton,SIGNAL(clicked()),this,SLOT(del()));
connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
connect(buttonBox,SIGNAL(rejected()),this,SLOT(reject()));
//layout
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(listView);
layout->addWidget(buttonBox);
setLayout(layout);
}
ListViewer::~ListViewer()
{
delete ui;
}
QStringList ListViewer::itemList() const
{
return model->stringList();
}
void ListViewer::insert()
{
int row = listView->currentIndex().row();
model->insertRows(row, 1);
QModelIndex index=model->index(row); //This class is used as an index into item models derived from QAbstractItemModel.
//The index is used by item views, delegates, and selection models to locate an item in the model.
listView->setCurrentIndex(index);
listView->edit(index);
}
void ListViewer::del()
{
model->removeRows(listView->currentIndex().row(),1);
}