在用QxtGlobalShortcut 时编译报错
C++
"QCFString::toQString(__CFString const*)", referenced from:
QxtWindowSystem::windowTitle(unsigned long long) in qxtwindowsystem_mac.o
解决方法,搬个砖
from https://stackoverflow.com/questions/9725113/convert-cfstringref-to-qstring
C++
QString QCFString::toQString(CFStringRef str)
{
if (!str)
return QString();
CFIndex length = CFStringGetLength(str);
if (length == 0)
return QString();
QString string(length, Qt::Uninitialized);
CFStringGetCharacters(str, CFRangeMake(0, length), reinterpret_cast<UniChar *>
(const_cast<QChar *>(string.unicode())));
return string;
}
将源码中代码改为
C++
QString QxtWindowSystem::windowTitle(WId window)
{
CGSValue windowTitle;
CGError err((CGError)noErr);
static CGSConnection connection = _CGSDefaultConnection();
// This code is so dirty I had to wash my hands after writing it.
// most of CoreGraphics private definitions ask for CGSValue as key but since
// converting strings to/from CGSValue was dropped in 10.5, I use CFString, which
// apparently also works.
// FIXME: Not public API function. Can't compile with OS X 10.8
// err = CGSGetWindowProperty(connection, window, (CGSValue)CFSTR("kCGSWindowTitle"), &windowTitle);
if (err != noErr) return QString();
CFStringRef str = (CFStringRef)windowTitle;
if (!str)
return QString();
CFIndex length = CFStringGetLength(str);
if (length == 0)
return QString();
QString string(length, Qt::Uninitialized);
CFStringGetCharacters(str, CFRangeMake(0, length), reinterpret_cast<UniChar *>
(const_cast<QChar *>(string.unicode())));
return string;
// this is UTF8 encoded
//return QCFString::toQString((CFStringRef)windowTitle);
}
发表评论