QT Notepad tutorial

  • Greetings,

    I am working on the QT Notepad tutorial. Unfortunately when I get a certain point I loose my way and I was wondering if you help me get past this hurdle.

    link to tutorial

    To add functionality to the editor, we start by adding menu items and buttons on a toolbar.
    Click on "Type Here", and add the options New, Open, Save, Save as, Print and Exit. This creates 5 lines in the Action Editor below. To connect the actions to slots, right-click an action and select Go to slot > triggered(), and complete the code for that given slot.
    If we also want to add the actions to a toolbar, we can assign an icon to each QAction, and then drag the QAction to the toolbar. You assign an icon by entering an icon name in the Icon property of the action concerned. When the QAction has been dragged to the toolbar, clicking the icon will launch the associated slot.

    However, I do not have the 5 action items that it describes. Could you help understand what I am doing wrong?


    QT Creator 4.5.0
    Based on Qt 5.10.0 (Clang 7.0 (Apple), 64 bit)
    MacOSX 10.13.3

  • Moderators

    your link doesn't point to a tutorial but to the docs of the QAction class?

    Anyway i can only tell how to do this programmatically and not with QtDesigner (since i never used it yet honestly). You need to create QAction instances and connect their triggered()-signal to custom slots. In there you do the work.
    For "new" you could call clear() on the textedit. For "open" you can open a QFileDialog, for "print" call print() on the textedit, for "exit" you could call QApplication::instance()->quit() for example.

  • @raven-worx
    You are correct. I copied the wrong link. Sorry that has been corrected. I copied the verbiage in the original post. You will be able to see the link now. It's very confusing. I am new to UI work and and QT. Just started about 5 hours ago.

  • Lifetime Qt Champion

    Creator seems not to create an action for a top menu.
    It works as sample says for sub items, but either i miss some little step in the description or
    it has changed since example was written.

    alt text

  • @mrjj
    Ok, let me play it with it. I will update this post if I can get it to work.

  • Ok, I see what is going on. I believe whomever wrote the guide was a little familiar with GT UI. So unfortunately, as I was not I got lost and completed the task wrong. What the guide should say is double click, "Type here" and change to "File". Then proceed to create the following items under "File".

    • New
    • Open
    • Save
    • Save as
    • Exit

    At this point the inaction items will be created for you. Unfortunately, my screen grabbing utility on Mac causes the file menu to collapse. So you can see it in the image. See example below.

  • Thank you to everyone who pitched in and helped. Viewing the screen grabs and comments I was able to piece together what I was doing wrong.

  • Lifetime Qt Champion

    Ah, now it all makes sense. :)
    Good work.
    Please feel free to ask about designer if you get stuck again.

  • @mrjj I most definitely will. I have a couple of projects that I want to create for both iOS, MacOSX and Windows. I am even considering a port to Linux. I think this might be the easiest way for me to do this. So far I am really enjoying this quest.

  • Lifetime Qt Champion

    Yes, Qt will help a loooong way making the app cross platform.
    Depending on what features you use, it might be a simple recompile and its running.
    Note that using virtual machines for each platform is often far less work then
    setting up cross compiling from one platform to the others.

    One note. When you use Designer, c++ code is generated for you.
    If you press F2 on ui->setupUi(this); in mainwindow constructor you can see
    how the UI is being created. This i found useful for understanding how stuff worked.
    Also if you add widgets dynamically to a Designer created class/form, always
    put it UNDER that line :)

  • @mrjj
    Right now I am trying to track down where to put the declarations of the inaction stuff. In my first project it was Class / private ....

    How do I clear out an old project?

  • @SeanR said in QT Notepad tutorial:

    Right now I am trying to track down where to put the declarations of the inaction stuff. In my first project it was Class / private ....

    How do I clear out an old project?

    Actually, I reset the project and started over. My old project was busted. The answer to my question was "private slot:"

  • Ok, so here is my next question. I have finally got the application semi working. I have an issue though. Please ignore the missing icons. I was just doing it for a test type thing.

    Why does my application not have a "File" & "Edit" menu??
    Yes, I can drag the icons out. But I really liked the fact the tutorial can have a file menu.


  • Qt Champions 2018

    @SeanR Isn't the application menu on the top bar in MacOS and not in the application window itself?

  • @jsulm said in QT Notepad tutorial:

    @SeanR Isn't the application menu on the top bar in MacOS and not in the application window itself?

    Good call. I being mostly a MacDev noob and tired failed to look up there. Ty, I was expecting to see on the application. Minus 50 dragon kill points for me...

Log in to reply

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