小问题解决方案

目录

error CS0246: 未能找到类型或命名空间名称“DllImport”(是否缺少 using 指令或程序集引用?)      

其他信息: 对 PInvoke 函数“useQtDllTest1!useQtDllTest1.Form1::screenShotToLocal”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。

Qt程序中文乱码

QT 5.12.12 QWebEngineView  浏览器点击链接崩溃(点击忽略有时候不崩溃) 

Qt 实现程序无边框效果,并支持鼠标拖动

获取电脑第一块硬盘的序列号

QWebEngineView 支持H5 Video标签 allowFullScreen 视频最大化最小化

windows静默卸载程序命令 

Qt Pro文件转为 VS  sln文件

Qt 将控件文本添加颜色


error CS0246: 未能找到类型或命名空间名称“DllImport”(是否缺少 using 指令或程序集引用?)      

using System.Runtime.InteropServices;

其他信息: 对 PInvoke 函数“useQtDllTest1!useQtDllTest1.Form1::screenShotToLocal”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。

[DllImport("qtdialog.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool screenShotToLocal(string sPath);

在DllImport(“qtdialog.dll”)后面增加 CallingConvention = CallingConvention.Cdecl)

Qt程序中文乱码

执行字符编码  可以在每个cpp文件添加

#pragma execution_character_set("utf-8")

QT 5.12.12 QWebEngineView  浏览器点击链接崩溃(点击忽略有时候不崩溃) 

QWebEngineView *MyWebengineView::createWindow(QWebEnginePage::WebWindowType type)
{

    if(type == QWebEnginePage::WebBrowserTab)
    {
        QWebEnginePage* new_page = new QWebEnginePage(this->page()->profile(), this);
        this->setPage(new_page);
    }

    return this;
}

Qt 实现程序无边框效果,并支持鼠标拖动

# .h  
    // 用来实现鼠标拖拽
    bool                    m_bMove;
    QPoint                  m_pos;

protected:
    void mousePressEvent(QMouseEvent *event);

    void mouseMoveEvent(QMouseEvent *event);

    void mouseReleaseEvent(QMouseEvent *event);

# .cpp
# QUpdateResource 是自己编写的类

setWindowFlags(Qt::FramelessWindowHint);
    
void QUpdateResource::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_bMove = true;
        m_pos = event->globalPos();
    }
}

void QUpdateResource::mouseMoveEvent(QMouseEvent *event)
{
    if (m_bMove)
    {
        QPoint moveDistance = event->globalPos() - m_pos;
        m_pos = event->globalPos();

        move(this->pos() + moveDistance);
    }
}

void QUpdateResource::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
        m_bMove = false;
}

获取电脑第一块硬盘的序列号

# cmd命令
wmic diskdrive where index=0 get serialnumber

#代码
    QString strCommand = QString("wmic diskdrive where index=0 get serialnumber");
    QProcess p;
    p.start(strCommand);
    p.waitForFinished();
    QString strResult = QString::fromLocal8Bit(p.readAllStandardOutput());
    QStringList strList = strResult.split(" ", QString::SkipEmptyParts);
    strResult = strResult.remove(strList.last(), Qt::CaseInsensitive);
    strResult = strResult.replace("\r", "");
    strResult = strResult.replace("\n", "");
    strResult = strResult.simplified();
    strResult = strResult.remove(QString("serialnumber"), Qt::CaseInsensitive);
    strResult = strResult.trimmed();

QWebEngineView 支持H5 Video标签 allowFullScreen 视频最大化最小化

#include <QWebEngineFullScreenRequest>

ui->webView->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);

connect(ui->webView->page(), &QWebEnginePage::fullScreenRequested, this, [=] (QWebEngineFullScreenRequest pageRequeset)
{
   pageRequeset.accept();
});

windows静默卸载程序命令 

/C wmic product where '(name=\"Java 8 Update 291\")' call uninstall

Java 8 Update 291 为程序名称

Qt Pro文件转为 VS  sln文件

qmake -tp vc xxx.pro

如果qt程序是一个subdir 包含了多个pro文件

qmake -r -tp vc xxx.pro

Qt 将控件文本添加颜色

<span style = color:blue>测试</span>


ui->labelResult->setText("<span style = color:blue>测试</span>");
ui->labelResult->setText("<p style = color:blue>测试</p>");

二者皆可将QLabel的文本颜色改为蓝色

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值