C++/Qt 小知识记录6

工作中遇到的一些小问题,总结的小知识记录:C++/Qt

dumpbin工具查看库导出符号

查看库中的符号,使用 /symbols 选项;如果想要查看导出的符号,可以使用 /exports 选项。

dumpbin /exports libprotobuf.lib
输出到文本
dumpbin /exports libprotobuf.lib > exports.txt

OSGEarth使用编出的protobuf库,报错问题解决

最近使用vs2022编译OSG3.6.5 + OSGEarth3.3,在编译时报错如下链接错误,将protobuf的很多个版本都尝试了也没有,以及大部分的解决方案说将编译改为动态库也不行:

	1>vector_tile.pb.obj : error LNK2019: 无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A),函数 "public: virtual class mapnik::vector::tile_value * __cdecl mapnik::vector::tile_value::New(void)const " (?New@tile_value@vector@mapnik@@UEBAPEAV123@XZ) 中引用了该符号
	1>glyphs.pb.obj : error LNK2001: 无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A)
	1>vector_tile.pb.obj : error LNK2019: 无法解析的外部符号 "struct std::atomic<bool> google::protobuf::internal::init_protobuf_defaults_state" (?init_protobuf_defaults_state@internal@protobuf@google@@3U?$atomic@_N@std@@A),函数 "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __cdecl google::protobuf::internal::GetEmptyString(void)" (?GetEmptyString@internal@protobuf@google@@YAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 中引用了该符号
	1>glyphs.pb.obj : error LNK2001: 无法解析的外部符号 "struct std::atomic<bool> google::protobuf::internal::init_protobuf_defaults_state" (?init_protobuf_defaults_state@internal@protobuf@google@@3U?$atomic@_N@std@@A)
	1>D:\Developer\OsgEarth3.3\build_vs2022\lib\Release\osgEarth.dll : fatal error LNK1120: 2 个无法解析的外部命令
	1>已完成生成项目“osgEarth.vcxproj”的操作 - 失败。
	========== 生成: 0 成功,1 失败,1 最新,0 已跳过 ==========
	========== 生成 于 20:44 完成,耗时 09.620 秒 ==========

解决方法:
在osgEarth的CMakeLists.txt中入PROTOBUF_USE_DLLS宏:
ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS)
即,让OsgEarth使用protobuf的动态库(所以protobuf至少也要编成动态库的形式)
参考链接:
https://blog.csdn.net/alvinlyb/article/details/110952210
c++编译protobuf时提示LNK2001 无法解析的外部符号_vc++编译protobuf无法解析的外部符号-CSDN博客

VS2022使用cpl模板后,提示会乱码的修改设置

VS2022使用cpl模板后,提示注释会乱码的修改
在这里插入图片描述
修改方法:选项->环境->区域设置内切换语言:
在这里插入图片描述

QProcess调用cmd.exe执行脚本

主要是当时忘了Windows下的cmd命令也是一个工具,就想着直接调用自己的执行命令去了,特此记录一下。
在这里插入图片描述

QPainterPath对线段描边处理

即:对一条粗线段进行描边,但在线段的交点容易产生缠绕的线,如图所示:
在这里插入图片描述
解决过程中发现:QPainterPathStroker的setWidth(n)和painter->strokePath(outlinePath, pen)传入的pen,设置pen.setWidth值一致,可以避免,入图所示:
但边线太粗,无法满足要求。
在这里插入图片描述
使用QPainterPath提供的simplified()函数处理转弯处的计算冗余问题,同时支持painter->strokePath(outlinePath, pen)传入的pen,线宽可以根据要求改变。
部分实现如下:

painter->setRenderHint(QPainter::Antialiasing, true);

// 生成可填充的轮廓
QPainterPathStroker stroker;
stroker.setCapStyle(Qt::RoundCap);
stroker.setJoinStyle(Qt::RoundJoin);
stroker.setDashPattern(Qt::SolidLine);
stroker.setWidth(m_attr.m_nLineWidth);

// 可填充区域,表示原始路径 path 的轮廓
QPainterPath path;
path.moveTo(m_attr.m_polygon[0]);
for (int i = 1; i < m_attr.m_polygon.size(); i++)
{
	path.lineTo(m_attr.m_polygon[i]);
}
QPainterPath outlinePath = stroker.createStroke(path);
outlinePath = outlinePath.simplified();

// 轮廓外边框绘制
QPen pen(m_attr.m_lineColor);
pen.setWidth(2);
painter->strokePath(outlinePath, pen);

// 填充路径 outlinePath
painter->setPen(Qt::NoPen);
QColor fillColor = m_attr.m_fillColor;
fillColor.setAlpha(120);
painter->fillPath(outlinePath, QBrush(fillColor));

QTableWidget实现行颜色交替的样式

在这里插入图片描述
以下为与之相关的qss和代码的实现:

/*设置QAbstractItemView隔行换色*/
QAbstractItemView[alternatingRowColors = "true"]{
	qproperty-alternatingRowColors:true;
}

QTableWidget {
	background-color: #66333333; /*背景色*/
	alternate-background-color: #07314f; /*交替色*/
	border: none; 
	font-size: 12px;
	color: #ffffff; 
	gridline-color: #77c4ff; /* 设置网格线的颜色 */
}
ui->tableWidget->setAlternatingRowColors(true); //设置支持
  • 19
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值