segmentation error caused by libGL.dylib`(glViewport)

OS: Sonoma 14.2.1 (23C71),

I am porting a linux code (that uses C++, QT) to mac OS. after compiling the code on mac, I get segmentation error due to libGL.dylib.

My question is how to avoid the segmentation error.

debug messages when I run it using lldb:

2024-03-21 13:13:17.957964+0530 EdgeMarker[10094:150997] SecTaskCopyDebugDescription: EdgeMarker[10094]/0#-1 LF=0
2024-03-21 13:13:18.962117+0530 EdgeMarker[10094:150997] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=10094
2024-03-21 13:13:18.962246+0530 EdgeMarker[10094:150997] SecTaskCopyDebugDescription: EdgeMarker[10094]/0#-1 LF=0
Process 10094 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xa80)
    frame #0: 0x00007ffa1c1295a4 libGL.dylib`glViewport + 22
libGL.dylib`glViewport:
->  0x7ffa1c1295a4 <+22>: movq   0xa80(%rax), %r9
    0x7ffa1c1295ab <+29>: movq   (%rax), %rdi
    0x7ffa1c1295ae <+32>: popq   %rbp
    0x7ffa1c1295af <+33>: jmpq   *%r9
Target 0: (EdgeMarker) stopped.

Backtrace snippet:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xa80)
  * frame #0: 0x00007ffa1c1295a4 libGL.dylib`glViewport + 22
    frame #1: 0x000000010000c427 EdgeMarker`MyGLCanvas::initializeGL(this=0x00007f8e4f857710) at MyGLCanvas.cpp:33:2

The error occurs when initializing an opengl window:

void MyGLCanvas::initializeGL()
{
	m_width = this->frameGeometry().width();
	m_height = this->frameGeometry().height();

	m_initialized = true;

	m_Eye[0] = 0.0f; m_Eye[1] = 0.0f; m_Eye[2] = -2.0f; //Actual code
	m_PerspectiveAngleDegrees = 45.0f;
	m_NearPlane = 0.01f;
	m_FarPlaneOffset = 100.0f;

	glViewport(0, 0, (GLint)m_width, (GLint)m_height);

Before calling MyGLcanvas::initializeGL() there is a call to setFocus() function. SetFocus is a function used in GUI programming to give focus to a specific window or control within a window.

My second question : Is setFocus valid is mac OS or is there an equivalent?