Invalid use of qualified-name



  • invalid use of qualified-name MainWindow::on_save_clicked()

    Any ideas as to why this has happened?

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QObject"
    #include "QtCore"
    #include "QNetworkConfigurationManager"
    #include "QNetworkInterface"
    #include "QHostAddress"
    #include "QString"
    #include "QFile"
    #include "QLineEdit"
    #include "QDir"
    #include "QApplication"
    #include "QMainWindow"

    MainWindow::MainWindow(QWidget *parent):
    QMainWindow(parent),
    ui(new Ui::MainWindow)

    {
    ui->setupUi(this);

    //display network interfaces
    QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
    
    // each interface is allocated one after the other in a list
    

    foreach (QNetworkInterface mon, list)

    //adding the list to be shown in the interface combobox
    {
    ui->comboBox_Interface->addItem(mon.name());
    }
    
    // a for loop that counts from 50-90 in multiples of 5
    for (int i = 50; i <= 90; i += 5)
    //selecting the combox alert to diplay the figures 50-90 with a % symbol
    {
        ui->comboBox_Alert->addItem(QString::number(i) + "%");
    }
    
    void MainWindow::on_save_clicked(); {
    
        // creating directory upon run for user input
    
        QDir mDir;
        mDir.mkpath("C:/Monice/BW");
    
        QString MBW = ("C:/Monice/BW/MBW.txt");
    
        QFile mFile&#40;MBW&#41;;
    
        if (mFile.open(QIODevice::WriteOnly))
        {
            QTextStream out(&mFile);
            out << ui->lineEdit->text();
        }
    

    }

    }

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

    @


  • Lifetime Qt Champion

    Hi,

    @
    void MainWindow::on_save_clicked(); { <- Why do you have semi-colon here ?

        // creating directory upon run for user input
    
        QDir mDir;
        mDir.mkpath("C:/Monice/BW");
    
        QString MBW = ("C:/Monice/BW/MBW.txt");
    
        QFile mFile&#40;MBW&#41;;
    
        if (mFile.open(QIODevice::WriteOnly))
        {
            QTextStream out(&mFile);
            out << ui->lineEdit->text();
        }
    

    }

    } <- this one is not at its place
    @

    Hope it helps



  • by not at its plae you mean not needed, i dont understand. now that i have removed the semicolon (super anoyyed about that xD) the error is that the the { is expected after another { and a function definition is not allowed before the }

    @
    void MainWindow::on_save_clicked()
    {

        // creating directory upon run for user input
    
        QDir mDir;
        mDir.mkpath("C:/Monice/BW");
    
        QString MBW = ("C:/Monice/BW/MBW.txt");
    
        QFile mFile&#40;MBW&#41;;
    
        if (mFile.open(QIODevice::WriteOnly))
        {
            QTextStream out(&mFile);
            out << ui->lineEdit->text();
        }
    

    }

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

    error occurs at frist and last } symbol



  • Hi, I think with "not at its place" he meant you need to put it at the right place, ant not delete it. :D
    i think you should move the "}" before the line
    @
    void MainWindow::on_save_clicked() {
    @
    because it looks like the closing bracket of your constructor?

    If you format your code properly something like that is easier to spot,
    Qt Creator can at least indent the code for you: select the code and press ctrl+I



  • Hi, your original post should look like that:

    @
    MainWindow::MainWindow(QWidget *parent):
    QMainWindow(parent),
    ui(new Ui::MainWindow)

    {
    ui->setupUi(this);

    //display network interfaces
    QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
    
    // each interface is allocated one after the other in a list
    

    foreach (QNetworkInterface mon, list)

    //adding the list to be shown in the interface combobox
    {
    ui->comboBox_Interface->addItem(mon.name());
    }
    
    // a for loop that counts from 50-90 in multiples of 5
    for (int i = 50; i <= 90; i += 5)
    //selecting the combox alert to diplay the figures 50-90 with a % symbol
    {
        ui->comboBox_Alert->addItem(QString::number(i) + "%");
    }
    

    } // <---- END CONSTRUCTOR
    void MainWindow::on_save_clicked() // <--- no ; here
    { // <----

        // creating directory upon run for user input
    
        QDir mDir;
        mDir.mkpath("C:/Monice/BW");
    
        QString MBW = ("C:/Monice/BW/MBW.txt");
    
        QFile mFile&#40;MBW&#41;;
    
        if (mFile.open(QIODevice::WriteOnly))
        {
            QTextStream out(&mFile);
            out << ui->lineEdit->text();
        }
    

    }

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



  • aaa i thought that was the case i just couldnt see it!

    thank you a lot for the comments problem solved :)


Log in to reply
 

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