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. Invalid use of qualified-name
QtWS25 Last Chance

Invalid use of qualified-name

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.3k Views
  • 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
    davidrhcp
    wrote on last edited by
    #1

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

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        davidrhcp
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Offline
            C Offline
            clochydd
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davidrhcp
              wrote on last edited by
              #6

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

              thank you a lot for the comments problem solved :)

              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