Variable does not name a type?

  • Hello, there!

    I'm a complete C++ and Qt n0b, so excuse me if this is a stupid question.

    I'm creating a password storage system, which will (at some point, when I get that far) save passwords in the form of hashes to a file.

    I've created a few variables, but they're giving me the error in the title.

    Here's the code I'm using:

    Ui::MainWindow *ui;
    string fileName;
    QString username;
    ifstream fileStream;
    void readFile();
    void createFile();
    void writeFile();

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <iostream>

    using namespace std;

    QString username = qgetenv("USER");
    string fileName = "/home/" + username + "/.passwordsafe/safe.bin";
    ifstream fileStream(fileName.c_str());

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    setWindowTitle("PasswordSafe by Beatsleigher | Linux Edition");
    if (fileStream.good())

    MainWindow::~MainWindow() {
    delete ui;

    void MainWindow::readFile() {


    void MainWindow::createFile() {


    void MainWindow::writeFile() {


    void MainWindow::on_actionAbout_triggered() {


    Any help with this issue is greatly appreciated. I've searched for a while, found nothing, and this error has been bugging me for over an hour, now.

    Thanks in advance.

  • It might help us to have the specific error and the line in which it occurs.

  • And one more thing, better do not mix STL and Qt like that. For writing to file you can use QFile.

  • By the way, Beatsleigher, Welcome to DevNet :)

Log in to reply

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