Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QApplication::exec: Must be called from the main thread
Forum Updated to NodeBB v4.3 + New Features

QApplication::exec: Must be called from the main thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hnderyH Offline
    hnderyH Offline
    hndery
    wrote on last edited by
    #1

    Hi again,
    i've got a question again again,,i know this is really unnecessary question.
    But u know.. "question = new question" :D
    i've got one lineEdit for entry url,one button for load and one webView for showing youtube videos.for videos i used youtube embed videos url. for simple explane;

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QNetworkProxyFactory>
    #include <QRegExp>
    
    
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    	ui->setupUi(this);
    	QNetworkProxyFactory::setUseSystemConfiguration (true);
    	QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
    	QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, true);
    }
    
    
    MainWindow::~MainWindow() {
    	delete ui;
    }
    
    
    void MainWindow::on_loadButton_clicked() {
    	QRegExp exp("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
    	exp.indexIn(ui->textURL->text());
    	if( exp.capturedTexts().length() >= 2 ) {
    		QString video_url = "http://www.youtube.com/embed/";
    		video_url += exp.capturedTexts().at(1);
    		ui->webView->load( QUrl( video_url ));
    	}
    }
    //https://www.youtube.com/watch?v=LsKFsF2zpFM
    //https://youtu.be/LsKFsF2zpFM
    

    trying to "https://www.youtube.com/watch?v=EIoBvWTzkTY&t=4s"
    and this work very well

    1.png

    except live broadcast videos

    when i try to open live broadcast ;
    "https://www.youtube.com/watch?v=21X5lGlDOfg" <<live link

    2.png

    Application Output:
    QApplication::exec: Must be called from the main thread

    why and how i fix that

    thanks your patience for my silly questions.have good day for all.

    kshegunovK 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You showed us a lot of stuff but nothing where you instantiate your QApplication which is what the error is about.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • hnderyH hndery

        Hi again,
        i've got a question again again,,i know this is really unnecessary question.
        But u know.. "question = new question" :D
        i've got one lineEdit for entry url,one button for load and one webView for showing youtube videos.for videos i used youtube embed videos url. for simple explane;

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QNetworkProxyFactory>
        #include <QRegExp>
        
        
        MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
        	ui->setupUi(this);
        	QNetworkProxyFactory::setUseSystemConfiguration (true);
        	QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
        	QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, true);
        }
        
        
        MainWindow::~MainWindow() {
        	delete ui;
        }
        
        
        void MainWindow::on_loadButton_clicked() {
        	QRegExp exp("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
        	exp.indexIn(ui->textURL->text());
        	if( exp.capturedTexts().length() >= 2 ) {
        		QString video_url = "http://www.youtube.com/embed/";
        		video_url += exp.capturedTexts().at(1);
        		ui->webView->load( QUrl( video_url ));
        	}
        }
        //https://www.youtube.com/watch?v=LsKFsF2zpFM
        //https://youtu.be/LsKFsF2zpFM
        

        trying to "https://www.youtube.com/watch?v=EIoBvWTzkTY&t=4s"
        and this work very well

        1.png

        except live broadcast videos

        when i try to open live broadcast ;
        "https://www.youtube.com/watch?v=21X5lGlDOfg" <<live link

        2.png

        Application Output:
        QApplication::exec: Must be called from the main thread

        why and how i fix that

        thanks your patience for my silly questions.have good day for all.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        To add to @Christian-Ehrlicher, setting QT_FATAL_WARNINGS in the environment can also give you stack trace about the warning, which'd be immensely helpful to track down where and why this happens.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        4

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved