What API does Qt use for interacting with the Windows clipboard? - qt

I've been browsing the Qt source code trying to find the actual system calls but it seems Qt doesn't use the Windows API documented on MSDN. For example grepping the source for "GetClipboardData" returns results in two files:
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
HANDLE clipData = GetClipboardData(CF_TEXT)
qaxserverbase.cpp:
STDMETHOD(GetClipboardData)(DWORD dwReserved, IDataObject** ppDataObject);
...
HRESULT WINAPI QAxServerBase::GetClipboardData(DWORD, IDataObject**)
{
return E_NOTIMPL;
}
and "SetClipboardData":
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
result = SetClipboardData(CF_UNICODETEXT, wcsdup(reinterpret_cast<const wchar_t *> (data->text().utf16()))) != NULL;
Neither of which seems useful, since they're being declared for Win CE/Mobile.

My Qt (4.8.1) uses OleSetClipboard and OleGetClipboard. The lines you got to are never reached in regular windows, as only in case of #if defined(Q_OS_WINCE) Qt uses #define OleSetClipboard QtCeSetClipboard and #define OleGetClipboard QtCeGetClipboard, and otherwise uses system-provided versions of those functions.
It was a little dificult to see this #if defined though, so you are excused ;)
It is so at least on my Qt version. If you are talking about qt, and especially about it's internals, you should menstion the version, right?

Related

DirectCompute D3DReflect GetConstantBufferByIndex always return null pointer

I'm trying to get reflection information for a compute shader compiled by my program by calling D3DCompile() or D3DCompile2().
Compilation is OK, confimed by code executing correctly.
Then I call D3DReflect to get a reflector against the compiled code.
Once I have the reflector, I call reflector->GetDesc(&ShaderDesc);
This works perfectly: ShaderDesc structure reports ConstantBuffers equal to 1 which is correct.
Then I call reflector->GetConstantBufferByIndex(0) which always returns the null pointer.
What is wrong ?
My environment: Windows 10 fully up-to-date, DirectX11 on NVidia Quadro K4200 with driver 24.21.14.1240 dated 21/07/2019, D3DCompiler_47.dll dated 19/03/2019.
Edit:
In the shader, the constant buffer is defined like this:
cbuffer TImageParams : register(b0)
{
int2 RawImageSize; // Actual image size in RawImage
// More items....
};
Kind regards

`_naked`: Trying to compile legacy 8051 (FX2) code with SDCC, newer version stumbles

I have legacy code for an embedded 8051 core (in a cypress FX2) that used to compile with other versions of SDCC. However, current SDCC doesn't know the _naked qualifier:
delay.c:27: syntax error: token -> '_naked' ; column 21
as triggered by
static void
udelay1 (void) _naked
{
_asm ; lcall that got us here took 4 bus cycles
ret ; 4 bus cycles
_endasm;
}
and other occurrences.
As _naked practically is supposed to tell the C compiler to "nah, ignore the fact that you're a C compiler and understand that you'd need to save frame context", I don't feel like I should just #define it away.
Is there any solution to this? Should I just go ahead and manually inline the assembler wherever a _naked function is used? I feel like I'd betraying the compiler on a CALL there, and that would change the timing.
_naked was replaced by __naked in newer versions of SDCC. Same applies to asm/__asm, at/__at, interrupt,bit,xdata/__….
So, this turned out to be an exercise in regex replacements.
I'm still having linker/ranlib/mostly ar problems, and CMake ignores what I instruct it to use as compilers, but oh well.

How to use QT and GNU Autotools by using AutoTroll?

I would like to use Autotools and QT4 together. For this i would like to use AutoTroll.
As the Website says, it should be very easy to use it. Unfortunately i was not able to do so.
I have a working Hello World example:
This is how my configure.ac looks like:
AC_INIT([Hello], [0.1], [bug-report#hello.example.com], [hello], [http://hello.example.com/])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.10 no-define foreign])
AC_PROG_CXX
AC_PROG_CC
AT_WITH_QT
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
My Makefile.am:
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
bin_PROGRAMS = hello
hello_SOURCES = src/*.cpp
My simple main.cpp with a QT include:
#include <iostream>
#include <QApplication> \\Added this to test if Autotools works correctly
int main()
{
std::cout << "Hello Worlasdasdsadd!" << std::endl;
return 0;
}
Can someone please help mit with this? An short Step by step would be very nice.
Thank you in advance.
Edit:
I don't know how to integrate this m4 makro (Autotroll) in my configuration. This is why i cannot provide any "Errors" or something else. The of the website does not help me to understand what to do.
I won't recommend you to mix QT and autotools. For QT projects is most recommended to use cmake/qmake. When you get any problems it would be easier to find answers, etc.
Furthermore, Autotroll seems unmaintained since 2008 and not tested with QT >= 4.4+, and it has rained a lot (really a lot, QML and QT 5.0 as examples) since then:
AutoTroll has been tested successfully with Qt 4.0+, Qt 4.1+, Qt 4.2+ and Qt 4.3+
If you just want to learn autotools, gtk/gnome, gnu-tools or just any c++/c/whatever-language project would make it easier for you. Find projects using autotools and learn what they need and what they use.
Another recommendation is that you look for presentations and talks explaining the autotools basis and tools flows.
All I can say is that Autotools is a big world, be patient.

glGenRenderbuffersEXT not declared but glGenFramebuffersEXT works

I am trying to use RBOs in a project which uses QGLWidget. Now, when I want to use RBOs for a fast read of a texture the compiler says 'glGenRenderbuffersEXT' was not declared in this scope. The same with FBO (glGenFramebuffersEXT) works fine.
The gl relevant includes I use:
#include <GL/glew.h>
#include <QtOpenGL>
I link against the glew library, too.
Here a dump of my CMakeLists.txt:
include_directories(
${GLEW_INCLUDE_PATH}
${PROJECT_SOURCE_DIR}/include
${OpenCV_INCLUDE_DIRS}
${CG_INCLUDE_PATH}
)
set(LIBS
${GLEW_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${CG_LIBRARY}
${CG_GL_LIBRARY}
${OpenCV_LIBS}
${GFlags_LIBS}
${QT_LIBRARIES}
common
ndiolib
optimization-static
LightingLib-static
)
SOURCE_GROUP("Shader Files" FILES ${SHADER_FILES})
add_executable(Relighting ${HDRS} ${SRCS} ${MOCSRC} ${SHADER_FILES} main.cxx)
target_link_libraries(Project ${LIBS})
Anybody has an idea, what could be wrong? When I tried to use glext.h (+gl.h) instead of glew.h, both the RBOs and the FBOs weren't found.
Side-question: Should I use RBOs for reading out a texture at all? Or is it equally fast to use the FBO which I use to read out the texture?
I check OpenGL site and it seems that the function you mentioned is defined only if you have GL_GLEXT_PROTOTYPES defined.
http://www.opengl.org/registry/api/glext.h
Further digging shows that you do need to define this symbol in order to use prototypes of extensions.
http://www.opengl.org/registry/ABI/#5

How to determine the platform Qt is running on at runtime?

Is there a (Qt) way to determine the platform a Qt application is running on at runtime?
Intention: While I hate to bring up a question
that is almost 2 years old, I think
that a good amended answer is valuable
to have on record so that others that
end up on this question can do it the
right way.
I can't help but notice that most of the answers recommend using the Q_WS set of macros to determine the Operating System, this is not a good solution, since Q_WS_* refers to the Windowing System and not the Operating System platform(for eg. X11 can be run on Windows or Mac OS X then what?), thus one should not follow those macros to determine the platform for which the application has been compiled.
Instead one should use the Q_OS_* set of macros which have the precise purpose of determining the Operating System.
The set currently consists of the following macros for Qt 4.8:
Q_OS_AIX
Q_OS_BSD4
Q_OS_BSDI
Q_OS_CYGWIN
Q_OS_DARWIN
Q_OS_DGUX
Q_OS_DYNIX
Q_OS_FREEBSD
Q_OS_HPUX
Q_OS_HURD
Q_OS_IRIX
Q_OS_LINUX
Q_OS_LYNX
Q_OS_MAC
Q_OS_MSDOS
Q_OS_NETBSD
Q_OS_OS2
Q_OS_OPENBSD
Q_OS_OS2EMX
Q_OS_OSF
Q_OS_QNX
Q_OS_RELIANT
Q_OS_SCO
Q_OS_SOLARIS
Q_OS_SYMBIAN
Q_OS_ULTRIX
Q_OS_UNIX
Q_OS_UNIXWARE
Q_OS_WIN32
Q_OS_WINCE
References:
Qt 4 https://doc.qt.io/archives/qt-4.8/qtglobal.html
Qt 5 https://doc.qt.io/qt-5/qtglobal.html
Qt 6 https://doc.qt.io/qt-6/qtglobal.html
NB: As mentioned by Wiz in the comments, Qt 5 completely removed the Q_WS_* set of macros, thus now all you can use are Q_OS_* ones.
Note that the Q_WS_* macros are defined at compile time, but QSysInfo gives some run time details.
To extend gs's function to get the specific windows version at runtime, you can do
#ifdef Q_WS_WIN
switch(QSysInfo::windowsVersion())
{
case QSysInfo::WV_2000: return "Windows 2000";
case QSysInfo::WV_XP: return "Windows XP";
case QSysInfo::WV_VISTA: return "Windows Vista";
default: return "Windows";
}
#endif
and similar for Mac.
If you are using a Qt version 5.9 or above, kindly use the below mentioned library function to retrieve correct OS details, more on this can be found here. There is also a QSysInfo class which can do some additional functionalities.
#ifdef Q_WS_WIN
#include <QOperatingSystemVersion>
switch(QOperatingSystemVersion::current())
{
case QOperatingSystemVersion::Windows7: return "Windows 7";
case QOperatingSystemVersion::Windows8: return "Windows 8";
case QOperatingSystemVersion::Windows10: return "Windows 10";
default: return "Windows";
}
#endif
For Qt5 I use the following:
logging.info("##### System Information #####")
sysinfo = QtCore.QSysInfo()
logging.info("buildCpuArchitecture: " + sysinfo.buildCpuArchitecture())
logging.info("currentCpuArchitecture: " + sysinfo.currentCpuArchitecture())
logging.info("kernel type and version: " + sysinfo.kernelType() + " " + sysinfo.kernelVersion())
logging.info("product name and version: " + sysinfo.prettyProductName())
logging.info("#####")
Documentation: http://doc.qt.io/qt-5/qsysinfo.html
Here is part of my code to detect windows or mac at run time and the version
#include <QSysInfo>
#include <QOperatingSystemVersion>
auto OSType= OSInfo.type();
auto OSInfo = QOperatingSystemVersion::current();
if (OSType !=1) //not windows os
{
return 0;
}
if (OSInfo < QOperatingSystemVersion::Windows7) // less than win7
{
return 0;
}

Resources