Answer the question
In order to leave comments, you need to log in
How to make variable available from another Qt C++ file?
Created a project through Qt Creator. It worked great, with static data. But I need the data to be taken from the passed arguments.
There is a main.cpp file:
#include "mainwindow.h"
#include <iostream>
#include <QApplication>
int main(int argc, char *argv[])
{
if (argc == 3) {
const char *title = argv[1];
const char *url = argv[2];
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle(title);
w.show();
return a.exec();
} else {
std::cout << "No ARGS" << std::endl;
return 0;
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->webView->load(QUrl(url)); //"https://ya.ru"
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
connect(ui->webView, &QWebView::linkClicked, this, &MainWindow::slotLinkClicked);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotLinkClicked(QUrl url)
{
ui->webView->load(url);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question