0

I am working in QT Creator.

I would like to mention that I am beginner in this software. I succeeded to create a menu that has: Edit and Open. I would like to create a new window when " Open " from menu bar is clicked. Till now I succeeded to print a message in QMessageBox when I press Open. What is the code for linking Open clicked with a new window? Is it possible to somehow drag and drop a new window in mainwindow.ui and than link it with Open on action Open_activated()?

THX . Appreciate

P.S I AM WORKING IN UBUNTU/C++ language

mtvec
  • 17,846
  • 5
  • 52
  • 83
skywak
  • 137
  • 3
  • 4
  • 10

2 Answers2

1

This is probably too late to answer but as I am also a beginner and struggled a lot to figure out this, I would like to share a solution that worked for me and according to me this is one of the simplest solution out there for a beginner.

Follow this link. It's possible that in the future that link might not exists, hence I am writing down a detailed version, as detailed as possible because I think for an absolute beginner (like myself) it can be very useful.

  1. Default mainwindow.cpp

mainwindow.cpp

  1. Go to "mainwindow.ui" (or whatever .ui one has)

.ui page

  1. Right-click outside the window and activate "Action Editor" if it wasn't already activated:

Action Editor

  1. Right-click on the window and create "Menu-bar" and then double-clicking on "type here" you can rename it as "Open" or something which will then drop-down another box where you can again type the name you desire, let's say "message".

menu-bar

type-here

menu-item message

  1. When created menu item "message" is created corresponding item will apear in the "Action Editor"

message in the action editor

  1. Right-click on the "message" in the Action Editor and click "go to slot" which will lead you to the specific slot in the mainwindow.cpp:

go to slot

enter image description here

  1. Here you can create a small window with whatever message you want to display.

[![Window creating code]11 etc goes here.]12

Codes that create a mini window and display some read-only text.

****don't forget to include "QTextEditor", go to mainwindow.h and #include "

enter image description here

On compiling & executing we will see :

click open->message->to open new window message window.

quanta
  • 215
  • 3
  • 14
0

Most of the question is already answered by this previous question. It leaves one part open, namely how that slot is called.

Well, you answered that: the menu entry "Open" is a QAction. You can connect that action to the slot which you just created.

Community
  • 1
  • 1
MSalters
  • 173,980
  • 10
  • 155
  • 350