Results 1 to 5 of 5

Thread: "QMainWindow: No such file or directory" error: Compiling using qmake only.

  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default "QMainWindow: No such file or directory" error: Compiling using qmake only.

    I'm trying to compile a qt project using terminal (Linux) qmake, but I'm getting the follwoing error message:
    I tried to follow this manual: https://doc.qt.io/qt-5/qmake-manual.html

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. QT_BEGIN_NAMESPACE
    7. namespace Ui { class MainWindow; }
    8. QT_END_NAMESPACE
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. MainWindow(QWidget *parent = nullptr);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. };
    21. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent)
    6. , ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QApplication>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. MainWindow w;
    9. w.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    main.pro
    Qt Code:
    1. HEADERS += mainwindow.h
    2. SOURCES += mainwindow.cpp
    3. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    [rob@archrob qteste]$ qmake main.pro
    [rob@archrob qteste]$ make
    g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o mainwindow.o mainwindow.cpp
    In file included from mainwindow.cpp:1:
    mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
    4 | #include <QMainWindow>
    | ^~~~~~~~~~~~~
    compilation terminated.
    make: *** [Makefile:663: mainwindow.o] Error 1

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.

    Add QT += widgets to your .pro file.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.

    Quote Originally Posted by d_stranz View Post
    Add QT += widgets to your .pro file.
    Ok, but now I'm getting this:
    [quote][/[rob@archrob qteste]$ make
    g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtWidgets -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o mainwindow.o mainwindow.cpp
    mainwindow.cpp:2:10: fatal error: ui_mainwindow.h: No such file or directory
    2 | #include "ui_mainwindow.h"
    | ^~~~~~~~~~~~~~~~~
    compilation terminated.
    make: *** [Makefile:668: mainwindow.o] Error 1quote]

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.

    Add this line to pro file :
    Qt Code:
    1. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: "QMainWindow: No such file or directory" error: Compiling using qmake only.

    And next will come the error about "Ui:: MainWindow" class being undefined because the one that -has- been defined has been put into a Qt namespace.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 6th December 2020, 18:06
  2. Replies: 12
    Last Post: 19th August 2015, 19:50
  3. Replies: 15
    Last Post: 6th March 2015, 14:34
  4. Replies: 2
    Last Post: 20th September 2013, 23:47
  5. Replies: 3
    Last Post: 15th February 2010, 18:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.