// 在文件最前面加下面代码
#pragma execution_character_set("utf-8") // 编译时把程序里的字符串使用 UTF-8 进行处理
// 在 main 函数加这个
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); // 使用 UTF-8 的运行时环境
QApplication::applicationDirPath()
setSelectionBehavior(QAbstractItemView::SelectRows); // 行选择
setSelectionMode(QAbstractItemView::SingleSelection); // 单选
setSelectionMode(QAbstractItemView::ExtendedSelection); // 多选(Ctrl、Shift、Ctrl+A都可以)
horizontalHeader()->setStyleSheet("QHeaderView::section{background-color:rgb(225,225,225)};"); // 列头灰色
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // 列宽自适应
horizontalHeader()->setHighlightSections(false); // 取消表头选择高亮
hideColumn(0); // 隐藏第0列 比如id
setModel(model); // 设置model
selectRow(row); // 选择第row行
setFocus(); // 设置为焦点
该类没加 Q_OBJECT
QByteArray byte_array="password";
// QCryptographicHash 不可逆
QByteArray md4_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Md4).toHex();
QByteArray md5_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Md5).toHex();
QByteArray sha1_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Sha1).toHex();
QByteArray sha256_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Sha256).toHex();
QByteArray sha512_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Sha512).toHex();
QByteArray sha3_256_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Sha3_256).toHex();
QByteArray sha3_512_byte_array=QCryptographicHash::hash(byte_array,QCryptographicHash::Sha3_512).toHex();
// Base64
QByteArray base64_byte_array=byte_array.toBase64(); // 加密
QByteArray decrypt_base64 QByteArray::fromBase64(base64_byte_array); // 解密
// 使用 QMap(std::initializer_list<std::pair<Key, T> > list) 构造函数
QMap<int,QString> map({{1,"One"},{2,"Two"}});
QList<int> list;
for(const auto &i : list){ // 只读
// i
}
for(auto &i : list){ // 读写
// i
}
for(auto i=list.cbegin(); i!=list.cend(); ++i){ // 只读
// *i
// i.value()
}
for(auto i=list.begin(); i!=list.end(); ++i){ // 读写
// *i
// i.value()
}
QMap<QString,QVariant> map;
for(auto i=map.cbegin(); i!=map.cend(); ++i){ // 只读
// i.key()
// i.value()
}
for(auto i=map.begin(); i!=map.end(); ++i){ // 读写
// i.key()
// i.value()
}
// QObject::connect(a, &A::Signal, b, [=](const QString &t) { b->Signal(t); });
// 2019-12-25 15:32:44 更新 可以直接转发 上面的 废除
QObject::connect(a, &A::Signal, b, &B::Signal);
QGuiApplication::screens().at(0)->size();
5.6.2
QString path_file = QStringLiteral("C:/test/test.txt");
QString file_path, file_name, base_name, file_suffix;
QFileInfo file_info = QFileInfo(path_file);
file_path = file_info.absolutePath(); // "C:/test" 文件路径
file_name = file_info.fileName(); // "test.txt" 完整文件名
base_name = file_info.baseName(); // "test" 文件名称
file_suffix = file_info.suffix(); // "txt" 后缀名
QString str = "10 06"; // 字符串
QByteArray hex = QByteArray::fromHex(str.toLatin1()); // \x10\x06
QByteArray hex = QByteArray::fromRawData("\x10\x06", 2);
QString str = temp.toHex(' ').toUpper(); // 10 06
// 创建菜单
__menu = new QMenu(this);
__action = new QAction("test", this);
__menu->addAction(__action);
// 添加到按钮
__ui->button->setMenu(__menu);
__ui->button->setStyleSheet("QPushButton::menu-indicator{image:none;}"); //不显示下拉图片 太丑了~
// __ui->button->setStyleSheet("QToolButton::menu-indicator{image:none;}");
// 实现按键点击事件
on_button_clicked() { // QPushButton 不需要主动显示菜单 且 不会进槽函数
__ui->button->showMenu(); // 这里QToolButton需要主动显示菜单
}
scrollToTop(); // 滚动到最前
scrollToBottom(); // 滚动到最后
QString uuid = QUuid.createUuid().toString().replace(QExp("[\\{\\}-]")."").toUpper();
bool b = str.contains(QRegExp("[\\x4E00-\\x9FA5]+")); // 中文的 区间在 [0x4e00,0x9fa5]
QStringList portNames;
auto portInfos = QSerialPortInfo::availablePorts(); // 获取全部串口
for (const auto &portInfo : portInfos) { // 查找可用的串口
if (portInfo.isValid() && !portInfo.isBusy()) { // 串口有效 且 串口空闲 2020-3-23 11:47:42 添加有效性检测
portNames.append(portInfo.portName());
}
}
qSort(portNames.begin(), portNames.end(), [](const QString &a, const QString &b) { // 自定义 按照 COM后面的数字大小排序
return a.mid(3, a.size() - 3).toInt() < b.mid(3, b.size() - 3).toInt();
}); // COMx 按x数字大小排序
// main.cpp
const char *qss = { #include "ui.qss" };
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
a.setStyleSheet(qss);
// ...
return a.exec();
}
setWindowFlags(Qt::WindowCloseButtonHint | Qt::MSWindowsFixedSizeDialogHint);
setWindowModality(Qt::ApplicationModal); //
QString name("test.db");
QRegExp("^[A-Za-z]{1}[A-Za-z0-9]{2,19}\.db$").exactMatch(name); //
double generateDouble(); // 生成一个0-1的随机浮点数
double bounded(double highest); // 生成一个0-highest的随机浮点数
quint32 bounded(quint32 highest);
int bounded(int highest); // 生成一个0-highest的随机整
quint32 bounded(quint32 lowest, quint32 highest);
int bounded(int lowest, int highest);
QRandomGenerator::global()->bounded(10); // 生成一个0和10之间的整数
QRandomGenerator::global()->bounded(10.0F); // 生成一个0和10.123之间的浮点数
QRandomGenerator::global()->bounded(10, 15); // 生成一个10和15之间的整数
QMenu *menuMain0 = QMenu("主菜单0");
QAction *actionMain0 = QAction("子菜单0");
menuBar->addAction(menuMain0->menuAction());
menuMain0->addAction(actionMain0);
// 以上是 ui 自动编译
// 代码里面这样插入
QAction *newAction = new QAction("主菜单1"); // 直接在 menuBar 的 QAction
ui->menuBar->insertAction(ui.menuMain0->menuAction(), newAction); // 插入
bool QDir::mkpath(const QString &dirPath) const;
QDir::setCurrent(QCoreApplication::applicationDirPath()); // 设置当前目录为 exe所在目录
bool QObject::inherits(const char *className) const;
QObject* obj = new QDoubleSpinBox();
obj->inherits("QDoubleSpinBox"); // true
obj->inherits("QAbstractSpinBox"); // true
obj->inherits("QObject"); // true
obj->inherits("QSpinBox"); // false
qApp->screens().indexOf(qApp->screenAt(QPoint(this->x(), this->y())));
isalpha()
是否只包含A-Za-z
isalnum()
是否只包含A-Za-z0-9
isdigit()
是否只包含0-9
from datetime import datetime,timezone,timedelta
datetime.fromtimestamp(timestamp/1000,tz=timezone(timedelta(hours=+8))).strftime('%y%m-%d %H:%M:%S.%f')[:-3]
json.dumps(j,sort_keys=False,indent=2,separators=(',',':'),ensure_ascii=False)
def convert_file_size(size): units=('K','M','G','T','P',) #定义单位列表 unit='B' #初始化单位为B for u in units: if size<1024: break size/=1024 unit=u return f'{round(size,2)}{unit}']]>
win10
slmgr /skms kms.digiboy.ir #服务器
slmgr /ato #激活
slmgr /dlv #查看激活状态
zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_vl_x14-74070
VLK:HCQ9D-TVCWX-X9QRG-J4B2Y-GR2TT
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced #regedit
DWORD(32位)值
ShowSecondsInSystemClock
1
重启
whoami #查看 计算机\用户名
#会立刻丢失当前用户下的所有EFS加密文件
#找回密码前请先解除当前用户下的所有文件的EFS加密
net user 用户名 密码 #你要重置的新密码
HKEY_LOCAL_MACHINE\System\GDI\Rotation #注册表
Angle #字段
0 #0度
5A #90度
B4 #180度
10E #270度
#重启生效
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace #regedit
找到项 数据为 Internet Explorer 的项 [ID各不同 以你自己的为准]
删除
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Notepad++]
@="Notepad++"
"Icon"="D:\\Notepad++\\notepad++.exe,0"
[HKEY_CLASSES_ROOT\*\shell\Notepad++\command]
@="D:\\Notepad++\\notepad++.exe %1"
set-executionpolicy remotesigned
gitee.com
为平台
ssh -T git@gitee.com
ssh-keygen -t rsa -C 'vanxkr'
git clone git@gitee.com:vanxkr/QQMusic_download.git
克隆仓库git branch
查看分支git branch vanxkr
创建分支git switch vanxkr
切换分支git switch -c vanxkr
创建并切换到分支git merge vanxkr
合并某分支到当前分支git branch -d vanxkr
删除分支git commit -m '修改信息'
提交git push origin master
提交主分支git checkout -- test.txt
恢复删除的文件git rm test.txt
git删除文件Microsoft Excel 开发人员参考手册
QAxObject *excel = new QAxObject();
QAxObject *work_books;
QAxObject *work_book;
QAxObject *work_sheets;
QAxObject *work_sheet;
QAxObject *work_cell;
QAxObject *obj;
if (excel->setControl("Excel.Application")) { // 使用office
LI << "使用Office";
} else if (excel->setControl("ket.Application")) { // 使用WPS
LI << "使用WPS";
} else {
QMessageBox::warning(this, tr("错误"), tr("未安装Office或WPS"));
return;
}
excel->setProperty("Visible", true); // 设置为可见
work_books = excel->querySubObject("WorkBooks"); // 操作表
work_books->dynamicCall("Add"); // 新建表格
excel->setProperty("Caption", "新建")) { // 设置主窗口标题栏中显示的名称
work_book = excel->querySubObject("ActiveWorkBook");
//work_book = work_books->querySubObject("Open(const QString&)", QDir::toNativeSeparators(template_path + template_name)); // 打开文件
work_sheets = work_book->querySubObject("Sheets");
work_sheet = work_sheets->querySubObject("Item(int)", 1);
work_sheet->setProperty("Name", "Datas"); //设置工作表名称
QVariantList table; // 区域数据
QVariantList line; // 区域数据的某行
table << QVariant(line); // 将一行放入区域数据
QString range = QStringLiteral("%1%2:%3%4").arg(Util::excelHCalc(1)).arg(1).arg(Util::excelHCalc(10)).arg(10); // A1:J10
work_cell = work_sheet->querySubObject("Range(const QString&)", range); // 获取区域
work_cell->setProperty("Value", QVariant(table)); // 填入区域数据
obj = work_cell->querySubObject("Font"); // 获取字体属性
obj->setProperty("Name", "新宋体"); // 设置字体
obj->setProperty("Size", "12"); // 设置字号
delete obj;
obj = work_cell->querySubObject("Interior"); // 获取单元格
obj->setProperty("Color", color); // 设置单元格颜色
delete obj;
delete work_cell;
work_cell = Q_NULLPTR;
// 冻结首行
excel->setControl("Excel.Application")
t = excel->querySubObject("ActiveWindow");
t->setProperty("SplitColumn", 0);
t->setProperty("SplitRow", 1);
t->setProperty("FreezePanes", true);
delete t;
work_book->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators("路径")); // 另存为
//excel->dynamicCall("Quit(void)"); // 关闭excel
// 一定要记得删除 不然一直在后台运行 占用内存
delete work_sheet; work_sheet = Q_NULLPTR;
delete work_sheets; work_sheets = Q_NULLPTR;
delete work_book; work_book = Q_NULLPTR;
delete work_books; work_books = Q_NULLPTR;
delete excel; excel = Q_NULLPTR;
/* windows头文件 #include <Windows.h> #include <tlhelp32.h> */ QTimer *t = new QTimer(); connect(t, &QTimer::timeout, [&]() { HWND hWnd = ::GetLastActivePopup(::GetForegroundWindow()); // 获得顶层窗口句柄 DWORD dwPID; GetWindowThreadProcessId(hWnd, &dwPID); // 获得句柄的PID HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // 获得系统进程快照句柄 PROCESSENTRY32 pe = { sizeof(pe) }; for (BOOL ret = Process32First(hSnapshot, &pe); ret; ret = Process32Next(hSnapshot, &pe)) { // 遍历 进程 if (pe.th32ProcessID == dwPID && "notepad.exe" == QString::fromWCharArray(pe.szExeFile)) { // 先判断PID 再判断 进程名称 LD << "notepad.exe 在最顶层 激活本程序"; activateWindow(); // 激活程序到最前 break; } } CloseHandle(hSnapshot); // 记得关掉快照句柄 }); t->start(100);]]>
#include <QDebug> #include <QDateTime> #if _DEBUG #define LI qInfo().noquote()<<QStringLiteral("%1(%2):%3(%4)[INFO ]").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__).arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")) #define LD qDebug().noquote()<<QStringLiteral("%1(%2):%3(%4)[DEBUG]").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__).arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")) #define LW qWarning().noquote()<<QStringLiteral("%1(%2):%3(%4)[WARN ]").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__).arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")) #define LC qCritical().noquote()<<QStringLiteral("%1(%2):%3(%4)[ERROR]").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__).arg(QDateTime::currentDateTime().toString("HH:mm:ss.zzz")) #else #define LI qInfo().noquote() #define LD qDebug().noquote() #define LW qWarning().noquote() #define LC qCritical().noquote() #endif]]>
x86 Native Tools Command Prompt for vS 2017
编译32位 x64编译64位
configure -prefix "C:\Qt\Qt5.15.3" -confirm-license -opensource -debug-and-release -platform win32-msvc -qt-sqlite -qt-zlib -qt-libpng -qt-libjpeg -nomake tests -nomake examples -mp
指定的安装目录为C:\Qt\Qt5.15.3
nmake
nmake install
C:\Qt\Qt5.15.3
执行qmake.exe -v
查看安装版本PS:
静态编译:
qtbase\mkspecs\common\msvc-desktop.conf
内容: MD
修改为MT
configure -static -prefix "C:\Qt\Qt5.15.3_static" -confirm-license -opensource -debug-and-release -platform win32-msvc -qt-sqlite -qt-zlib -qt-libpng -qt-libjpeg -nomake tests -nomake examples -mp
推荐使用Jom编译: 推荐使用Jom
替代nmake
多线程 编译 效率翻N倍: https://wiki.qt.io/Jom
configure.bat
-static //指明是静态编译
-prefix "C:\Qt\Qt5.15.3" //指明安装的目录
-confirm-license -opensource //指明是开源版本的qt
-debug-and-release //指明需要debug版和release版
-platform win32-msvc //指明使用msvc编译
-qt-sqlite -qt-zlib -qt-libpng -qt-libjpeg //可选插件
-nomake examples -nomake tests //不编译样例
-mp //多核编译
github.com
C:\Windows\System32\drivers\etc\hosts
TTL
最小的一个 hosts