Properties of the Qmainwindow don’t work



  • I created a qt gui application. added...
    @QMainWindow.setDisabled(false);@ to the mainwindow.cpp file

    ran it and got the error... mainwindow.cpp:9: error: expected unqualified-id before '.' token.
    I am trying to test out some of the properties of the Qmainwindow but they do not work. what i am doing wrong?

    main.cpp
    @#include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }@

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QMainWindow.setDisabled(false);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@



  • @QMainWindow.setDisabled(false);@
    Actually it's not about Qt. It's about C++.
    Try to replace it with:
    @this->setDisabled(false);@
    Or simply with:
    @setDisabled(false);@



  • if i wanted to use qmainwindow.setDisabled(false); in a different function outside of MainWindow::MainWindow that what would i use then?



  • Seems like you're totally new to C++ and OOP in general.
    Try to read some tutorials on C++ programming.

    P.S.:
    @
    MainWindow w;
    w.setDisabled(true);
    @



  • yes I am fairly new to c++. I understand conditional statements and a bit of functions. thank you for your help.



  • Hi kalster,

    setDisabled is a method of the class QWidget and there fore also for each derived class.
    If you are inside the class (so inside the derived classes members) you can directly call it. If you are outside (or want to call it for another object) you have to use the target object as selector:

    @
    MainWindow w;
    w.setDisabled(true);
    @

    or

    @
    QCheckBox* pCheck;
    pCheck->setDisabled(true);
    @


Log in to reply
 

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