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. Issue with QtWidgets (Complete beginner)

Issue with QtWidgets (Complete beginner)

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 331 Views 2 Watching
  • 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.
  • S Offline
    S Offline
    SoWeBegin
    wrote on last edited by
    #1

    Hi, I'm a complete beginner with Qt. I just installed and already have some issues.
    I'm currently following this tutorial to create a Notepad small application: https://doc.qt.io/qt-5/qtwidgets-tutorials-notepad-example.html

    Everything works fine until I finish the "Designing the application" step.
    I have two issues:
    First one = in the Design section, I can't use "Layout" for my Text Edit widget. I can't understand why.
    The second issue = In the tutorial, it literally says that my Notepad header file should have multiple functions automatically "Spawned" by Qt, so it should look like this:

    #include <QMainWindow>
    
    namespace Ui {
    class Notepad;
    }
    
    
    class Notepad : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit Notepad(QWidget *parent = nullptr);
        ~Notepad();
    
    private slots:
        void newDocument();
    
        void open();
    
        void save();
    
        void saveAs();
    
        void print();
    
        void exit();
    
        void copy();
    
        void cut();
    
        void paste();
    
    

    But instead, my header looks like this:

    #ifndef NOTEPAD_H
    #define NOTEPAD_H
    
    #include <QMainWindow>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class Notepad; }
    QT_END_NAMESPACE
    
    class Notepad : public QMainWindow
    {
        Q_OBJECT
    
    public:
        Notepad(QWidget *parent = nullptr);
        ~Notepad();
    
    private:
        Ui::Notepad *ui;
    };
    #endif // NOTEPAD_H
    
    

    Basically, the class in my header has 0 functions. Only constructor, and destructor.

    Thanks for the help in advance!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to the forum.

      I can't use "Layout" for my Text Edit widget. I can't understand why.

      the tutorial has it slightly wrong. To lay out a widget in its parent select the parent (so click anywhere outside the text edit in this case) and then the lay out options are available.

      In the tutorial, it literally says that my Notepad header file should have multiple functions automatically "Spawned" by Qt, so it should look like this:

      Again it's a bit poorly worded in the context of the following code snippet. It says that "The wizard generated a header file for the Notepad class that has the necessary #includes, a constructor, a destructor, and the Ui object." and that part is true, but what it should say after that is that everything else not mentioned above is added as part of that exercise, so those functions you create yourself. The wizard generates a basic class like you posted and that is ok.

      S 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        Hi, welcome to the forum.

        I can't use "Layout" for my Text Edit widget. I can't understand why.

        the tutorial has it slightly wrong. To lay out a widget in its parent select the parent (so click anywhere outside the text edit in this case) and then the lay out options are available.

        In the tutorial, it literally says that my Notepad header file should have multiple functions automatically "Spawned" by Qt, so it should look like this:

        Again it's a bit poorly worded in the context of the following code snippet. It says that "The wizard generated a header file for the Notepad class that has the necessary #includes, a constructor, a destructor, and the Ui object." and that part is true, but what it should say after that is that everything else not mentioned above is added as part of that exercise, so those functions you create yourself. The wizard generates a basic class like you posted and that is ok.

        S Offline
        S Offline
        SoWeBegin
        wrote on last edited by
        #3

        @Chris-Kawa I can't believe it was this simple. Thank you for the quick & informative answer, it helped a lot!

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi and welcome to the forums

          First one = in the Design section, I can't use "Layout" for my Text Edit widget. I can't understand why.

          Well first place the TextEdit on the form.
          Then right click any where on the form (not hitting the TextEdit)
          Then in the popup menu, goto Layout submenu and choose a layout there.

          alt text

          Yeah that example skips some steps and its not really clear.

          Those slots
          void open();
          void save();

          you should just paste them to your code. they wont auto spawn.

          We use them to in the connect statement for the buttons in the toolbar

          connect(ui->actionOpen, &QAction::triggered, this, &Notepad::open);
          connect(ui->actionSave, &QAction::triggered, this, &Notepad::save);

          ...

          ahh. to slow :)

          1 Reply Last reply
          1
          • P Offline
            P Offline
            pishavar
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            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