How to disable web security policy? I tried many ways but failed. I use qt5.9.2

  • This post is deleted!

  • I run QWebEngineView browser on my arm board. The browser page can not display normally. I think it is "Same Origin Policy" stop the browser loading some files. I have tried three ways, but it seems to useless.
    First way,
    webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
    webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);

    Second way,
    Pass argument "--disable-web-security" or "--disable-web-security --user-data-dir='mydir' " to QApplication object.
    Third way,
    Pass argument "--allow-file-access-from-files" to QApplication object, useless. But i tried command "chrome.exe --allow-file-access-from-files" on Windows, it success.

    Anyone can give me some suggestions?

  • Removed duplicate

    Please don't post the same question multiple times. I am erasing the other one.

  • @ambershark Could you tell me how to solve this problem?

  • @kingstying Sorry I haven't used QWebEngine components enough to offer much advice there. And in the little I have used them I've never had to mix remote/local files that require security overrides.

    Hopefully someone else who has done it can chime in here.

  • This post is deleted!

  • I'm using the flag "--disable-web-security" with QWebEngineView with success on Qt 5.9.X and Qt 5.10

    I don't use "--allow-file-access-from-files" flag since I don't need to access local files ...

  • @DeeeZ Thanks you very much. Could you please tell me how do you pass the "--disable-web-security" argument to QWebEngineView? Do you pass it to QApplication object?

  • Like this:
    QStringList argumentsAdded;
    int i = 0;
    int new_argc = argc + argumentsAdded.size();
    char** new_argv = (char **) malloc((new_argc + 1) * sizeof (char *));

    // Store previous arguments
    for(i = 0; i < argc; i++)
        size_t length = strlen(argv[i])+1;
        new_argv[i] = (char *) malloc(length);
        memcpy(new_argv[i], argv[i], length);
    // Store new arguments
    foreach(QString s, argumentsAdded)
        new_argv[argc + i]  = new char[s.toLocal8Bit().size()+1];
        strcpy( new_argv[argc + i], s.toLocal8Bit().constData());
    // Finish array with NULL value
    new_argv[new_argc] = NULL;
    // Create a single application to avoid to have several instance
    QtSingleApplication singleApp(new_argc, new_argv);

Log in to reply