I tried to use Windows api PageSetupDlg in Qt to save some time. However, I get errors during compilation in the title. Here is my code:
#include <QtCore/QCoreApplication>
#include <windows.h>
#include <QDebug>
int main(int argc, char *argv[])
{
PAGESETUPDLG lppsd;
QCoreApplication a(argc, argv);
//#ifdef Q_WS_WIN
// MessageBox(NULL,TEXT("This is windows window"),
// TEXT("HAHAYOYO"),MB_OK);
PageSetupDlg(&lppsd);
//#endif
return a.exec();
}
I ‘ve added the LIBS += -LC:\Windows\System32\ComDlg32.dll in the .pro file, however it doesn’t work. I’m not sure whether it is correct to write like that.
My second question is that do I need to add the #ifdef & #endif statements when I try to call a Windows API function? Since the MessageBox function runs correctly without them.
you need to add
Comdlg32.lib, notComDlg32.dllwhich is a dll, not an include library.Though why not just use
QPrintDialog? Also, you need to initialize thePAGESETUPDLGvariable if you plan on using it, see this.You should add them, if you intend on running on a non-Windows system, the WinAPI will most certainly not be available (and cause of this you should use
QMessageBox), however, if you system is dependant on WinAPI functions, then there is no point, because you’ll be bound to Windows regardless.