English 中文(简体)
QT/C++是另一个关于查阅情报和安全局档案的问题
原标题:QT/C++ yet another issue about accessing UI files

虽然我读到了这个问题的答案。

QT/C++ - Accessing MainWindow UI from a different class and searched the whole www for quite some time - I don t get it working.

交给我的任务是利用QT设计师重整一个应用程序。 不幸的是,在几个班级中已经出现过一些倡议(小组随后跨越了想法,使用QT,但并未使用设计人,而“手编码”看来没有什么意义)

因此,我现在的工作是打破公开目的,建立一个全球倡议(一个可以找到所有可能的信号和位置,把它放在一起看清冰和清洁。

So much for the theoretical part.

增补:在C++方面,我几乎没有经验,似乎在找回答案的地方找不到,在明天之前没有时间读整本书,否则我会问。

我有两点:

A) My mainwindow.cpp, mainwindow.h and mainwindow.ui need to be linked into other files e.g. the previewwidget.cpp... the previewwidget.cpp had a lot of code like:

 buttonLayout->addWidget(fpsSpinBox, 0, Qt::AlignCenter);
 buttonLayout->addWidget(playButton, 0, Qt::AlignCenter);
 buttonLayout->addWidget(backwardButton, 0, Qt::AlignCenter);

apparently I replaced it by creating the corresponding buttons in Designer. now in the same file theres the connect SIGNAL SLOT entries (I added the "ui->")

 connect(ui->playButton, SIGNAL(clicked()), this, SIGNAL(playButtonClicked()));
 connect(ui->stopButton, SIGNAL(clicked()), this, SIGNAL(stopButtonClicked()));
 connect(ui->forwardButton, SIGNAL(clicked()), this, SIGNAL(forwardButtonClicked()));

但是,汇编者仍然告诉我:

previewpwidget.cpp:77: Error: ui is notclar in this scope

我把“主人”放在头上,但这也不是解决办法。


<>/> 这个问题很可能与第一个问题密切相关:由于设计者trick熟地将模型/观点/控制分开,我需要改写信号和位置,以适应新的“国际倡议”——任何人是否为我提供良好的指导,或者为我提供什么内容,以便我如何迅速和毫不相干?

任何帮助都将受到高度赞赏。

最佳回答

让我们假设有一个称为<代码>MyWidget的班级和相应的<代码>ui文档MyWidget.ui。 为了在您的级别上加以利用,我将采取以下行动:

  • 在<代码>MyWidget.ui中,对<代码>objectName有价值。 如果你向设计师开立档案,它就将第一个财产放在财产编辑中。 页: 1 MyWidget

  • 在<代码>MyWidget.h 你必须做以下工作:

    • Declare a namespace for the ui object and forward declare it.
    • Add as member variable (private) a pointer to the ui object.

样本目录如下:

#ifndef MY_WIDGET_H_
#define MY_WIDGET_H_

#include <QWidget>

namespace Ui {
    class MyWidget;
}

class MyWidget : public QWidget {
   Q_OBJECT
public:
   MyWidget(QWidget* parent = NULL);
   ~MyWidget();

   // Add other class functions
private:
   Ui::MyWidget ui;
}   

#endif // MY_WIDGET_H_
  • In the MyWidget.cpp
    • Include the automatically generated ui_MyWidget.h
    • Create a new ui object in the constructor
    • Call the setupUi function in the constructor
    • Delete the ui in the destructor

样本代码:

#include "MyWidget.h"
#include "ui_MyWidget.h"

MyWidget::MyWidget(QWidget *parent)
:QWidget(parent), ui(new Ui::MyWidget)
{
    ui->setupUi(this);
}

MyWidget::~MyWidget()
{
    delete ui;
}

现在,你准备在你整个班子里利用你。 举例来说,如果您有一个称为的轴心箱,则以Box1。 2. 贵

int val = ui->spinBox1->value();

.ui Signals and Slots

我将建议你使用<代码>QtDesigner,以便使植被和位置联系起来。 www.un.org/chinese/ga/president

如果你想把植被与习惯分位联系起来,你可以再次这样做: a 设计人

  1. Switch to Edit Signals/Slots mode (F4)
  2. Drag and drop from the widget which it to emit the signal, to the widget which is to receive the signal.
  3. A Configure Connection dialog appears, showing the signals for the emitting widget, and the slots for the receiving widget. Click Edit... below the slots column on the right.
  4. A Signals/Slots of ReceivingWidget dialog appears. In here its is possible to click the plus icon beneath slots to add a new slot of any name.
  5. You can then go back and connect to your new slot in the Configure Connection dialog, or indeed in the Signal/Slot Editor dockwidget back in the main window.
问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签