How to solve undefined references, is the library not imported, or other problems - win32gui

I'm trying to use Win32 GUI project on a project, but when I compile it, I get a lot of undefined reference errors.
||=== Build: Debug in 05.9.finally (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function Z4OpenP6HWND__':|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|61|undefined
reference towglCreateContext#4'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|63|undefined
reference to wglMakeCurrent#8'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|65|undefined
reference toglClearColor#16'| obj\Debug\main.o||In function
Z4Initv':|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|76|undefined
reference toglBlendFunc#8'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|77|undefined
reference to glClearColor#16'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|78|undefined
reference toglClearDepth#8'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|79|undefined
reference to glDepthFunc#4'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|80|undefined
reference toglEnable#4'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|81|undefined
reference to glShadeModel#4'|
C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|82|undefined
reference toglHint#8'| obj\Debug\main.o||In function `Z6Draw3Dv':|
#include <GL/gl.h>
#include <GL/glut.h>
#include <windows.h>
GLfloat step = 0.0f;
HINSTANCE hInstance; // 系统实例句柄
HWND hWndMain; // 主窗体句柄
HWND hWnd; // 窗体句柄变量定义
HDC hDC; // 设备描述表变量定义
PIXELFORMATDESCRIPTOR pfd; // 像素格式结构变量定义
HGLRC hGLRC; // OpenGL渲染描述表变量定义
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // 窗体过程函数声明
GLboolean keys[256];
GLfloat rotStep = 30.0f;
void keyPress();
GLuint Open(HWND phWnd)
{
hWnd = phWnd;
hDC = GetDC(hWnd);
pfd.dwDamageMask = 0; // 忽略层遮罩
int pixelformat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, pixelformat, &pfd);
hGLRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hGLRC);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // 初始化背景为灰色
return 0;
}

You includes have a forward slash in the naming. Maybe you wanted #include "path/name".

I believe you would have solved it by now; in case not then you can try providing correct library path. Use command line options -L for path to library folder and -l for library name while compiling/linking.
An online lookup for OpenGL suggests the library file names may be any or all from these: opengl32.a or opengl32.lib, glu32.a or glu32.lib, freeglut.a or freeglut.lib (choose .a if you are building on Linux or .lib on Windows).

Related

Using QGLFramebufferObject and shaders without QGLWidget

I want to create an OGL data processor using QGLFunctions shaders and framebuffers. I don't need any widgets. But to create valid Shader and framebuffer instances, I need a valid QGLContext with support for the appropriate glExtensions.
With zero context, of course, nothing works. With context of zero QPaintDevice too. With Qpixmap as device it creates a valid context, but it lacks glExtensions for Shader and framebuffer.
#include <QGLFramebufferObject>
#include <QGLShaderProgram>
#include <QtOpenGL/QGLFunctions>
// ...
void GLProcessor::init()
{
auto format = QGLFormat::defaultFormat();
if (!context()){
m_context = new QGLContext(format, new QPixmap(1, 1));
bool ok = m_context->create();
qDebug() << "CREATING CONTEXT "<< ok;
Q_ASSERT(context()->isValid());
}
context()->makeCurrent();
initializeGLFunctions(context());
m_binFBO = new QGLFramebufferObject(lowsize ,lowsize ,QGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RED);
m_outFBO = new QGLFramebufferObject(lowsize ,1 ,QGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RED);
setupShaders();
// ...
}
There is an option, of course, to do as always is to get the context from the QGLWidget and hide it. But somehow inelegant. PS CUDA, OpenCL, AMP and so on I don't need. For my tasks need OpenGL.
How do I use shaders and framebuffers in qt4 without creating a QGLWidget?

Qstring to LPCWSTR

LPCWSTR path;
void WinApiLibrary::StartProcess(QString name)
{
path = name.utf16();
CreateProcess(path, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
}
C:\kursovaya\smc\winapilibrary.cpp:21: error: invalid conversion from
'const ushort* {aka const short unsigned int*}' to 'LPCWSTR {aka const
wchar_t*}' [-fpermissive]
path = name.utf16();
This code worked in the Qt 4.8, but now i have Qt 5.2 and this code isn't working. What's wrong with this guy?
I had the same issue (I'm using Qt 5.3), this is how I fixed it:
QString strVariable1;
LPCWSTR strVariable2 = (const wchar_t*) strVariable1.utf16();
QString::utf16() returns const ushort*, which is different from const wchar_t*, so you have the compile error.
You are probably compiling with /Zc:wchar_t. If you change it to /Zc:wchar_t- it should work, as wchar_t type becomes typedef to 16-bit integer in this case.
In Visual Studio: Project Properties->Configuration Properties->C/C++->Treat WChar_t As Built in Type->No.
Or just add reinterpret_cast<LPCWSTR>.
I'm using Qt 5.2 and I had the same issue. This is how I fixed it:
QString sPath = "C:\\Program File\\MyProg";
wchar_t wcPath[1024];
int iLen = sPath.toWCharArray(wcPath);
In the Qt global namespace, there is the macro qUtf16Printable. However as the documentation states, this produces a temporary so take care to use it properly. Note this was introduced in Qt5.7.

Extracting icon using WinAPI in Qt app

I'm trying to extract icon from exe file using WinAPI, but it doesn't work.
Here's the code:
QIcon OSTools::AppsInterface::extractAppIcon(const QString &fileName) const {
wchar_t *convertedName = new wchar_t[fileName.length() + 1];
fileName.toWCharArray(convertedName);
convertedName[fileName.length()] = '\0';
HICON Icon = ExtractIcon(NULL, convertedName, 0);
QPixmap pixmap = QPixmap::fromWinHICON(Icon);
return QIcon(pixmap);
}
Code outputs:
QPixmap::fromWinHICON(), failed to GetIconInfo()
(ExtractIcon function on MSDN).
I think problem is that I send NULL instead of "A handle to the instance of the application calling the function". But, generally, I use Qt, and it's only one WinAPI function in my app.
What's wrong? What's correct way to extract icon using WinAPI? If you have another function proposal, please, give me an example. This is the first time I'm using WinAPI.
UPDATE: Yes, there is a better way. You may use QFileIconProvider class for doing such things.
Works for me, even with NULL. But obtaining the HINSTANCE is actually very simple. You have a problem elsewhere i guess. Does your target exe really have an embedded icon?
#ifdef Q_WS_WIN
#include <qt_windows.h>
#endif
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifdef Q_WS_WIN
QString fileName("D:\\_dev\\eclipse\\eclipse.exe");
wchar_t *convertedName = new wchar_t[fileName.length() + 1];
fileName.toWCharArray(convertedName);
convertedName[fileName.length()] = '\0';
HINSTANCE hInstance = ::GetModuleHandle(NULL);
HICON Icon = ::ExtractIcon(hInstance, convertedName, 0);
ui->label->setPixmap(QPixmap::fromWinHICON(Icon));
#endif
}
I used QFileIconProvider, and it worked perfectly. Try this :
QPushButton b;
b.show();
QIcon icon;
QFileIconProvider fileiconpr;
icon = fileIconProvider.icon(QFileInfo("/*file name*/"));
b.setIcon(icon);
// And you can also save it where you want :
QPixmap pixmap = icon.pixmap( QSize(/*desired size*/) );
pixmap.save("/Desktop/notepad-icon.png");
Source. Have a nice day.
And solution was very simple. I just sent path to '.lnk' file instead of path to file. That's my inattention.

force call to QString(const char *) constructor in Qt 4.7

I am trying to compile a library written in Qt 4.6. On my current Linux machine I have only Qt 4.7 installed. The following code part:
/*file try.h*/
void fileOpen(QString s = NULL) ;
/*file try.cpp*/
void MainWindow::fileOpen(QString s) {
QString filename ;
if(s.isNull()) filename = QFileDialog::getOpenFileName(
this,
"Choose a file",
".",
"Source file (*.)");
else filename = s ;
}
compiles with the following error (I used cmake but the corresponding line code is the one listed above):
In member function ‘virtual int MainWindow::qt_metacall(QMetaObject::Call, int,
void**)’:
/homes/combi/hodorog/Developments/axelOld/build/axel/src/QGui/moc_MainWindow.cxx:141:26:
error: conversion from ‘long int’ to ‘QString’ is ambiguous
/homes/combi/hodorog/Developments/axelOld/build/axel/src/QGui/moc_MainWindow.cxx:141:26:
note: candidates are:
/usr/include/QtCore/qstring.h:426:43: note: QString::QString(const char*)
/usr/include/QtCore/qstring.h:105:14: note: QString::QString(const QChar*)
So I am guessing the problem is that in qt. 4.7. there are two QString constructors that can take a pointer as an argument (as listed in the compilation error), whereas in qt 4.6. there is only one QString constructor that can take a pointer as an argument. How can I force QString to call the constructor with const char * as an argument?
Thank a lot for your help in advance,
madalina
void fileOpen(QString s = NULL);
You are trying to construct a QString object with 0. It seems you are confusing the null of pointers with a null QString. A null QString is one which is created with the constructor QString(). Given how your function is implemented (referring to s.isNull()), you should change the function declaration to
void fileOpen(QString s = QString());

Proper QUuid usage in Qt ? (7-Zip DLL usage problems (QLibrary, QUuid GUID conversion, interfaces))

I'm trying to write a program that would use 7-Zip DLL for reading files from inside archive files (7z, zip etc).
Here's where I'm so far:
#include <QtCore/QCoreApplication>
#include <QLibrary>
#include <QUuid>
#include <iostream>
using namespace std;
#include "7z910/CPP/7zip/Archive/IArchive.h"
#include "7z910/CPP/7zip/IStream.h"
#include "MyCom.h"
// {23170F69-40C1-278A-1000-000110070000}
QUuid CLSID_CFormat7z(0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
typedef int (*CreateObjectFunc)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
void readFileInArchive()
{
QLibrary myLib("7z.dll");
CreateObjectFunc myFunction = (CreateObjectFunc)myLib.resolve("CreateObject");
if (myFunction == 0) {
cout << "CreateObject resolve failed!";
return;
}
else {
cout << "CreateObject resolved";
}
CMyComPtr<IOutArchive> outArchive;
myFunction(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
readFileInArchive();
return a.exec();
}
Trying to build that in Qt Creator will lead to following error:
cannot convert 'QUuid*' to 'const GUID*' in argument passing
How should QUuid be correctly used in this context?
Also, being a C++ and Qt newbie I haven't yet quite grasped templates or interfaces, so overall I'm having trouble getting through these first steps. If someone could give tips or even example code on how for example an image file could be extracted from ZIP file (to be shown in Qt GUI later on*), I would highly appreciate that.
My main goal at the moment is to write a program with GUI for selecting archive files containing image files (PNG, JPG etc) and displaying those files one at a time in the GUI. A Qt based CDisplayEx in short.
You have to explicitly cast QUuid to GUID:
QUuid boo;
GUID uid = static_cast<GUID>(boo);
You must use some conversion between the 2 types.
Looking at Qt documentation, I found that there is a GUID operator that transform a QUuid to a Windows GUID : http://doc.trolltech.com/4.6/quuid.html#operator-GUID
Of course, this is not cross-plateform.

Resources