比如在vc2008里Debug时函数的传入参数都变成0xCCCCCCCC之类,需对工程属性设置一下:
C/C++->优化->优化->禁用
人,技术,生活。
比如在vc2008里Debug时函数的传入参数都变成0xCCCCCCCC之类,需对工程属性设置一下:
C/C++->优化->优化->禁用
源码参见https://www.codeleading.com/article/62852336906/
提示
1 2 3 4 | error C2065: “STORAGE_PROPERTY_QUERY”: 未声明的标识符 error C2065: “StorageDeviceProperty”: 未声明的标识符 error C2065: “PropertyStandardQuery”: 未声明的标识符 error C2065: “IOCTL_STORAGE_QUERY_PROPERTY”: 未声明的标识符 |
按F1在msdn上查到的可能结果为
1 | #include <Ntddstor.h> |
但加了还是编译不通过,其实正确的是只要加入
1 | #include <WinIoCtl.h> |
程序启动时去掉dos窗口
1 | #pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup") |
DoModal
1 2 3 4 | DlgTst dlg(this); int result = dlg.exec(); if (QDialog::Accepted == result) QMessageBox::information(this, "title", "done."); |
Modelless
1 2 3 | DlgTst* dlg2 = new DlgTst(this); // dlg2->setModal(Qt::ApplicationModal); dlg2->show(); |
嵌入子对话框
1 | setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); |
保持对话框前置,类似于MFC的SetOwner
1 | setWindowFlags(Qt::Dialog); |
PostMessage
signal slot connect的默认行为类似于SendMessage,如果要实现PostMessage的行为,connect时加参数Qt::QueuedConnection。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class MainWindow : public QMainWindow { ... private slots: void on_pushButton_clicked(); void on_pushButton_2_clicked(); signals: void mySignal1(); }; MainWindow::MainWindow(QWidget* parent) { ... connect(this, SIGNAL(mySignal1()), SLOT(on_pushButton_2_clicked()), Qt::QueuedConnection); } void MainWindow::on_pushButton_clicked() { QMessageBox::information(this, "title", "on_pushButton_clicked 1"); emit mySignal1(); QMessageBox::information(this, "title", "on_pushButton_clicked 2"); } void MainWindow::on_pushButton_2_clicked() { QMessageBox::information(this, "title", "B"); } |
安装完qt-vs-tools-msvc2013-2.0.0.vsix后,重启vs2013,工程项目右键菜单上qt功能选项为灰色无效,怎么办?
打开.vcxproj修改
1 | <Keyword>Win32Proj</Keyword> |
为
1 | <Keyword>Qt4VSv1.0</Keyword> |
再重启vs,在工程上右键菜单上点击“Convert Project to Qt VS Tools Project”。
生成要翻译的语言文件
1 2 3 4 | lupdate hello.pro -ts lang.ts # or in cmake add_custom_target(tr COMMAND ${Qt5_LUPDATE_EXECUTABLE} -target-language en ${Srcs} -ts "${CMAKE_CURRENT_SOURCE_DIR}/lang.ts") lrelease lang.ts -qm lang.qm |
窗口上画矩形
1 2 3 4 5 6 7 | void DlgTst01::paintEvent(QPaintEvent *e) { QPainter painter(this); painter.setBrush(Qt::red); painter.setPen(Qt::red); painter.drawRect(QRect(0, 0, this->width(), this->height())); } |
支持c++20
1 2 | # CMakeLists.txt set(CMAKE_CXX_STANDARD 20) |
禁止背景重绘
1 | ui->widgetVideo->setUpdatesEnabled(false); |
皮肤skin
https://blog.csdn.net/weixin_42126427
http://t.zoukankan.com/luoxiang-p-13528745.html
无边框窗体的拖动和改变大小
https://www.cnblogs.com/warmlight/p/12841968.html
https://blog.csdn.net/zhushentian/article/details/82021838
Qt Style Sheets Reference
export QT_DEBUG_PLUGINS=1
refer to:
https://blog.csdn.net/qq_24127015/article/details/95118124
https://blog.csdn.net/zyx4843/article/details/50682212
https://blog.csdn.net/ermzdy2/article/details/99692954
https://blog.csdn.net/aaa123524457/article/details/80582978
http://www.myexception.cn/qt/1119616.html
https://blog.csdn.net/hl1hl/article/details/85244451
https://stackoverflow.com/questions/48187569/qt-translation-file-is-removed-on-make-clean-using-cmake
This macro exists in MacOS, On Linux, Add
1 | -msse -mfpmath=sse -ffast-math |
to gcc/g++ cmdline.
app/src/main/java/com/euhat/rtsp/euhatrtspdemo/MainActivity.java
108 109 | // try to modify the 3rd parameter to 0. mEuhatPlayer.open(url, 8000, 0, 1000, fps, 300); |
euhatrtsp/livevideo/RtspOp.cpp
389 390 391 392 393 394 395 396 397 | int EuhatRtspOp::decodingProc() { … //frame是原始H264数据,在这里录像最好,此库已经把ffmpeg库编译进去了,直接用ffmpeg库就可以完成录像功能。 //可以网上搜ffmpeg录像api怎么用。 //这就要求会写C++代码,还要加jni接口提供给java端打开或关闭录像功能。 decoder_->decode(frame + 4, *(int *)frame); … } |
比如在链接时会出现一大堆warning LNK4099,在代码中写
1 | #pragma warning(disable:4099) |
是无法禁止这些警告的,正确方法是在项目属性Properties->Linker->Command Line中添加
1 | /ignore:4099 |
当程序写得越来越大,进程占用的内存也就越来越多,调用popen时会返回空的FILE指针,网上说原因是system或popen这样的系统函数,其内部实现是调用fork函数创建子进程,创建过程中会复制父进程堆、栈等资源,这样就容易造成创建失败,返回NULL。
以下是我写的用vfork替换fork调用的Vpopen类。
Vpopen.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #pragma once #include <stdio.h> #include <sys/types.h> #include <unistd.h> class Vpopen { FILE *fp_; pid_t pid_; int pipeFd_[2]; public: Vpopen(); ~Vpopen(); FILE *open(const char *cmd, const char *flags); void close(); }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #define FILL_STYLE_VERTICAL 0 #define FILL_STYLE_HORIZONTAL 1 void fillGradientRect(HDC hdc, RECT *rc, COLORREF fromRGB, COLORREF toRGB, int fillStyle) { BITMAPINFO bmpInfo; memset(&bmpInfo, 0, sizeof(bmpInfo)); bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = rc->right - rc->left; bmpInfo.bmiHeader.biHeight = rc->bottom - rc->top; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = 32; bmpInfo.bmiHeader.biCompression = BI_RGB; BYTE *rgbBuffer = (BYTE *)malloc(bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biHeight * 4); int width = bmpInfo.bmiHeader.biWidth; int height = bmpInfo.bmiHeader.biHeight; int rStart = fromRGB & 0xFF; int rEnd = toRGB & 0xFF; int gStart = (fromRGB & 0xFF00) >> 8; int gEnd = (toRGB & 0xFF00) >> 8; int bStart = (fromRGB & 0xFF0000) >> 16; int bEnd = (toRGB & 0xFF0000) >> 16; if (FILL_STYLE_VERTICAL == fillStyle) { double rStep = (rEnd - rStart) * 1.0 / height; double gStep = (gEnd - gStart) * 1.0 / height; double bStep = (bEnd - bStart) * 1.0 / height; for (int y = 0; y < height; y++) { BYTE r = (BYTE)(rStart + rStep * y); BYTE g = (BYTE)(gStart + gStep * y); BYTE b = (BYTE)(bStart + bStep * y); for (int x = 0; x < width; x++) { BYTE *p = rgbBuffer + ((height - y) * width - (width - x)) * 4; *p++ = b; *p++ = g; *p++ = r; } } } else { double rStep = (rEnd - rStart) * 1.0 / width; double gStep = (gEnd - gStart) * 1.0 / width; double bStep = (bEnd - bStart) * 1.0 / width; for (int x = 0; x < width; x++) { BYTE r = (BYTE)(rStart + rStep * x); BYTE g = (BYTE)(gStart + gStep * x); BYTE b = (BYTE)(bStart + bStep * x); for (int y = 0; y < height; y++) { BYTE *p = rgbBuffer + ((height - y) * width - (width - x)) * 4; *p++ = b; *p++ = g; *p++ = r; } } } StretchDIBits(hdc, rc->left, rc->top, width, height, 0, 0, width, height, rgbBuffer, &bmpInfo, DIB_RGB_COLORS, SRCCOPY); free(rgbBuffer); } void CMFCApplicationDlg::OnPaint() { CPaintDC dc(this); CRect rc(50, 50, 200, 200); fillGradientRect(dc.m_hDC, rc, RGB(255, 0, 255), RGB(0, 255, 0), FILL_STYLE_HORIZONTAL); CDialogEx::OnPaint(); } |
1 2 3 | ::ReleaseCapture(); ::SendMessage(m_hWnd, WM_NCLBUTTONDOWN, HTCAPTION, NULL); ::SendMessage(m_hWnd, WM_LBUTTONUP, NULL, NULL); |