Qt

[Solution] QSslSocket: cannot call unresolved function SSLv3_client_method

Problem

When you try to open a HTTPS URL with QSslSocket or QNetworkAccessManager class, you get the following errors:

QSslSocket: cannot call unresolved function SSLv3_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function ERR_get_error
QSslSocket: cannot call unresolved function ERR_error_string

Solution

You need to install OpenSSL Win32 or Win64 binaries.

  1. Open Win32 OpenSSL Installation Project page.
  2. Download the latest “light” Win32 or Win64 installation package, for example “Win32 OpenSSL v0.9.8l Light”.
  3. Install it to any location. Ignore “Microsoft Visual C++ 2008 Redistributables” warning (click OK) and select copying OpenSSL DLLs to “The OpenSSL binaries (bin) directory”.
  4. Copy libeay32.dll and ssleay32.dll from the bin folder to the same place where your QtNetwork4.dll or QtNetworkd4.dll is located.
    原文:传送门

QML: rendering problems after minimizing frameless window

因为在做界面时正好遇到了这个问题,怎么调都调不通,后来一搜发现果然是Qt的bug,至今未修复啊同学……有个凑合的解决方法,但貌似不适用于纯qml界面,只适合混合的

原文看这里:传送门

I’m trying to implement the QML-based UI inside of frameless (Qt::FramelessWindowHint) window.
But QML engine stops responding to mouse clicks after window is minimized via showMinimized() method.

the code follows:

Image {
source: “minimize.png”
scale: mouse.pressed ? 0.8 : 1.0
smooth: mouse.pressed

MouseArea {
    id: mouse
    anchors.fill: parent
    anchors.margins: -5
    onClicked: {
        console.log("MinimizeButton clicked");
        viewer.showMinimized(); // If comment out this line, works fine
    }
}

}
 

After clicking on MouseArea window is minimized as needed. But all Qt Quick controls inside window become frozen after window has been restored.
Windows without Qt::FramelessWindowHint flag are not affected.
showMinimized() is not the only method to reproduce, “Show Desktop” command of OS gives the same effect. OS is Windows XP.

Is there any workaround for this problem?

 

解决方法:



obsessed, we also experienced this problem in one of our projects.
This bug is reported [bugreports.qt.nokia.com] but is not solved yet. Following the link to the bug report, you’ll find this workaround:
void MainWindow::showEvent(QShowEvent *event)
{
QApplication::postEvent(this, new QEvent(QEvent::UpdateRequest), Qt::LowEventPriority);
QWidget::showEvent(event);
}

 

Qt系统按钮本地化

Qt默认的系统按钮,比如Qt::Yes、Qt::No等需要在QDialog或QMessageBox中的按钮,在设计时是中文的,可在运行期却变成了英文。

本地化的方法是(代码中还有UTF编码的防乱码方法,懒得删了):

#include "framemain.h"
#include <QApplication>
#include <QTextCodec>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QTranslator translator(0);
    translator.load("qt_zh_CN.qm");
    QApplication a(argc, argv);
    a.installTranslator(&translator);
    //把编码设置为utf8,防止乱码
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
    frameMain w;
    w.show();

    return a.exec();
}

QObject: Cannot create children for a parent that is in a different thread

困扰了我一晚上,怀疑是插件机制的问题,然后把插件都去掉了,直接把代码写进线程里还是有问题。

最后还是今天早上搞明白的,在run()里用new新建基于qobject的对象时,千万别传入this指针啊,那是主线程的指针,相当于在子线程里为主线程建立了对象,所以出现跨线程警告。

解决QScrollArea不能出现滚动条的问题

QScrollArea实在是一个非常强大的控件,节省了很多重复工作。

但如果使用Qt Creator中的ui designer来制作界面的话,就会出现滚动条无法出现的问题。而在《C++ GUI Programming with Qt4, Second Edition》中由于是代码生成界面,没有此问题。有不少人碰到这个问题,就因此觉得“designer中生成是错的,代码生成是正确的”的这种想法,试问奇趣公司的天才能设计出Qt这种最伟大的框架,却连设计器都没好好测试就放出release了?开玩笑吧。

网上甚至还有个网友很“技术”地分析了这个问题,写了整整2大篇分析文章(点击打开),图文并茂而且还用了控件的提升改进等方法,还说是布局的QSizePolicy的问题。

谁能想到真正的问题和解决方法如此简单,用ui designer拖入的QScrollArea的widgetResizable属性是true,而用代码生成控件时默认构造器指定这个值是false。

真正的解决方法是在designer中将此值改为false,或在运行过程中执行setWidgetResizable(false)。

QAbstractListModel的数据更新问题

为QListview绑定了一个自定义model(由QAbstractListModel继承),在更新数据时总是出现“ASSERT: index.isvalid”并且crash掉,仔仔细细地又看了遍书,发现在数据更新后需要调用reset()通知view更新数据,以免因元素数量变更而造成index无效。

慎用elementsByTagName()函数

今天在对基础parse模块进行单元测试,在用自建XML进行测试时发现了一些莫名的小bug。

当然又是一顿查错,最后发现问题在于elementsByTagName函数,它竟然是大小写敏感(case insensitive)的!!这种着实下流的设计……也就是说找“Node1”是不会找到“node1”的。

这样的话在调用各家的open api时,可靠性就完全依赖人品了,太不安全了,哎,基础模块小规模重构。