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. Problem with static
Forum Updated to NodeBB v4.3 + New Features

Problem with static

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.5k 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.
  • D Offline
    D Offline
    developer
    wrote on last edited by
    #1

    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;
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aabc
      wrote on last edited by
      #2

      What error do you get ?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aabc
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

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