PDA

View Full Version : How to implement QGLFormat with QGLContext



litedrive
23rd January 2012, 00:56
What I'd like to know is how pass my QGLFormat object to QGLContext?

When I try to do this:


QGLFormat mFormat = QGLFormat( QGL::DepthBuffer | QGL::AlphaChannel );

QGLContext mContext = QGLContext( mFormat );

I get this error:



error: 'QGLContext::QGLContext(const QGLContext&)' is private


Using Qt Creator with Windows 7.

What is wrong here?

stampede
23rd January 2012, 20:10
Change


QGLContext mContext = QGLContext( mFormat );

to


QGLContext mContext( mFormat );

I think compiler "thinks" you want to use copy-constructor, which is private. But in fact the copy-constructor will not be used in this case. Look here:


#include <iostream>

class T
{
public:
T(){
std::cout << "T()\n";
}
T(const T&){
std::cout << "T(const T&)\n";
}
T(int){
std::cout << "T(int)\n";
}
T& operator=(const T& t){
std::cout << "T& operator\n";
}
};

int main(){
T t = T(10);
return 10;
}

This should print T(int), which means the copy-constructor is not used. But this:


#include <iostream>

class T
{
public:
T(){
std::cout << "T()\n";
}
T(int){
std::cout << "T(int)\n";
}
T& operator=(const T& t){
std::cout << "T& operator\n";
}
private:
T(const T&){
std::cout << "T(const T&)\n";
}
};

int main(){
T t = T(10);
return 10;
}

does not compile:

test.cpp: In function 'int main()':
test.cpp:54:3: error: 'T::T(const T&)' is private
test.cpp:60:12: error: within this context
(tested with g++ 4.5.2)