The code is the same as the example of the tutorials for opening a window. And the code for the button click is created when I attach a slot to a GUI button. So, it's auto generated code. I'm just putting the tutorial code in a function instead of main so that the function is called whenever the button is clicked. If you still insist on seeing the code, then,
void Widget::on_Generate_Button_clicked()
{
Open_Window();
}
void Widget::Open_Window()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.display();
}
}
However, there is no point in me posting this since this is the same tutorial code copy pasted to my program copy pasted here. I'm pretty sure the error is not Qt or SFML specific. It's more about the general C++ concept of passing of control from a function to another function within its scope. I thought I'd post it here because, usually, the SFML window function does not return the control until the window is closed. Is there any way to bypass it?
Here's what I what:
At
3:58, the person opens one window and while this window is running, opens another at
4:46. He is able to use the button on the Qt Widget even though the window is running (He uses DirectX). That's what I want exactly. To have control of the button while the window is running. As of now, my program is not doing that, and crashing if I try to do that.