Problem with static



  • hi all,
    i am creating a web browser in which i have a QLineEdit sub classed class name searchbar it is a search bar.
    i am creating one instance of searchbar in my MainWindow class i want it to be accesed by other classes staticilly
    i have created a static function that i will output that variable (its a pointer) but i am getting a error i have tried making the vriable search bar static but it does not works
    here is the source code mainwindow.cpp file
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    showMaximized();
    tabs = new QTabWidget();
    topwidget = new QWidget();
    toplayout = new QHBoxLayout(topwidget);
    view = new webview();
    view->load(QUrl("http://www.google.com/"));
    mainwidget = new QWidget();
    layout = new QVBoxLayout(mainwidget);
    locationbar = new QLineEdit();
    globalsearchbar = new searchbar();
    globalsearchbar->setFixedWidth(300);
    layout->addWidget(tabs);
    tabs->addTab(view , "google");
    setCentralWidget(mainwidget);
    QObject::connect(view , SIGNAL(urlChanged(QUrl)) , this , SLOT(updatelocation(QUrl)));
    QObject::connect(locationbar , SIGNAL(returnPressed()) , this , SLOT(gotourl()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    void MainWindow::updatelocation(QUrl url)
    {
    locationbar->setText(url.toString());
    }
    void MainWindow::gotourl()
    {
    QUrl location = locationbar->text();
    if(location.isValid())
    {
    view->load(location);
    }
    }
    void MainWindow::on_actionNew_tab_triggered()
    {
    newtab();
    }
    void MainWindow::newtab()
    {
    webview * webpage = new webview();
    tabs->addTab(webpage , "new tab");
    }
    static searchbar * MainWindow::getglobalsearchbar()
    {
    return globalsearchbar;
    }
    @



  • What error do you get ?


  • Moderators

    You can not return non-static member variables from a static method. So did you declare globalsearchbar to be static?



  • You need to use non-static method or return a static member


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.