Showing posts with label qt. Show all posts
Showing posts with label qt. Show all posts

Wednesday, February 1, 2012

[Solution] Qt Creator steals debug output from DebugView

Symptoms

When Qt Creator is running, DebugView shows only small amount of application debug output (generated by qDebug or OutputDebugString functions).

According to Qt Creator developers, this is not a bug but a feature.

Solution

Start DebugView before Qt Creator.

Wednesday, March 2, 2011

Qt version changes

Here is the place where you can find out what had changed between Qt public releases:
http://qt.nokia.com/developer/changes/

A link that can't be found easily.

Tuesday, September 28, 2010

[Solution] QProcess::startDetached cannot start process that requires elevated privileges in Microsoft Windows Vista, Windows Server 2008 or Windows 7

When running under Microsoft Windows Vista, Windows Server 2008 or Windows 7 with User Account Control (UAC) enabled, the following code always fails if starting a program that requires elevated privileges (it can be, for example, a setup program):

    QString exeFileName;

/.../

if (!QProcess::startDetached(exeFileName))
{
// error handling
}


The inner reason for this failure is that QProcess::startDetached method under Windows internally calls CreateProcess function. CreateProcess called from a non-elevated process fails with ERROR_ELEVATION_REQUIRED if it tries to start an executable that requires elevation.

Corresponding error report in Qt Bug Tracker was rejected because it "sounds like a reasonable limitation of QProcess".

Below is a possible solution for this problem. In short: QProcess::startDetached is replaced with ShellExecute function.

#ifdef Q_OS_WIN
#include <windows.h>
#include <shellapi.h>
#endif

/.../

QString exeFileName;

/.../


#ifdef Q_OS_WIN
int result = (int)::ShellExecuteA(0, "open", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
if (SE_ERR_ACCESSDENIED == result)
{
// Requesting elevation
result = (int)::ShellExecuteA(0, "runas", exeFileName.toUtf8().constData(), 0, 0, SW_SHOWNORMAL);
}
if (result <= 32)
{
// error handling
}
#else
if (!QProcess::startDetached(exeFileName))
{
// error handling
}
#endif

Wednesday, April 7, 2010

[Solution] How to make a Qt thread sleep?

First, consider using sleep(), msleep() or usleep() static methods of QThread class.

However, they are marked as protected, so you can call them only in a QThread subclass.

If for some reason you can't use QThread methods, the following small utility class will help you:

#include <QWaitCondition>
#include <QMutex>

class Sleep
{
 
public:
    
    // Causes the current thread to sleep for msecs milliseconds.
    static void msleep(unsigned long msecs)
    {
        QMutex mutex;
        mutex.lock();
 
        QWaitCondition waitCondition;
        waitCondition.wait(&mutex, msecs);
 
        mutex.unlock();
    }
};

Monday, November 16, 2009

[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.

Thursday, November 12, 2009

[Solution] QWebView does not show GIF or JPEG images

Problem

QWebView does not show GIF and/or JPEG images.

Solution

  1. In the directory where your Qt application is located, create a subdirectory with imageformats name.
  2. Copy there image plug-ins from the following directory: $(QTDIR)\plugins\imageformats
See more: Deploying an Application on Windows: Qt Plugins

Thursday, October 15, 2009

How to convert String to QString

QString StringToQString(String^ string)
{
    pin_ptr<const wchar_t> chars = PtrToStringChars(string);
    return QString::fromUtf16((const ushort*)chars);
}


See also: How to convert QString to String

Wednesday, October 14, 2009

How to convert QString to String

String^ QStringToString(const QString& string)
{
    return gcnew String((const wchar_t*)string.utf16());
}


See also: How to convert String to QString