在Qt中,我试图设置一个QTimer每秒调用一个名为"更新"的函数.这是我的.cpp文件:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include "QDebug"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::update()
{
qDebug() << "update";
}
Run Code Online (Sandbox Code Playgroud)
主要:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
该项目正在构建,但它没有执行更新,因为"更新"行没有显示在任何地方......有人看到我做错了吗?
我已经编程了Qt一段时间了,我想知道这两种情况之间有什么区别:
情况1:
标题:
QPushButton * button;
Run Code Online (Sandbox Code Playgroud)
源文件:
button = new QPushButton(this);
button->setText("Button");
button->resize(100,100);
Run Code Online (Sandbox Code Playgroud)
和
案例2:
标题:
QPushButton button;
Run Code Online (Sandbox Code Playgroud)
资源:
button.setParent(this);
button.setText("Button");
button.resize(100,100);
Run Code Online (Sandbox Code Playgroud)
两者都产生一个按钮,但是什么时候应该使用前者而后者呢?这两者有什么区别?
I would like to use CMake and clang-tidy in my project, however I see that build times are quite a bit higher when I use this in all the main cmake file:
set(CMAKE_CXX_CLANG_TIDY
clang-tidy-11;
-format-style='file';
-header-filter=${CMAKE_CURRENT_SOURCE_DIR};
)
Run Code Online (Sandbox Code Playgroud)
It is working well, but I don't want to have this build-time penalty every time I build the project during development. Therefore I thought I would make a separate target that builds all, but uses clang-tidy. And when I do a regular debug …
我正在尝试创建一个退出按钮,正确关闭我在QT中创建的GUI.我尝试过以下方式:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
int window_width = QApplication::desktop()->width();
int window_height = QApplication::desktop()->height();
MainWindow w;
QPushButton * quit_btn = new QPushButton;
quit_btn->setParent(w.centralWidget());
quit_btn->setGeometry(window_width-50,12,32,32);
QObject::connect(quit_btn,SIGNAL(clicked()),qApp,SLOT(quit()));
w.resize(window_width,window_height);
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我按下按钮时,调试器会出错:
Invalid address specified to RtlFreeHeap( 003E0000, 0028F950 )
Run Code Online (Sandbox Code Playgroud)
任何人都能指出我正确的方向吗?
我有一个使用 QML 文件的 Qt (5.8.0) 项目。我想使用 Qt creator (4.2.1) 在 QML 文件中设置断点,以便我可以遵循流程。但是我无法让它工作。我在 qmake 构建步骤中启用了“启用 QML 调试和分析”,并在运行步骤中启用了“启用 C++”和“启用 QML”。
C++ 代码中的断点被命中,但 QML 被忽略。启动时,我收到以下消息:
QDeclarativeDebugServer: Ignoring
\"-qmljsdebugger=port:42715,block,services:DebugMessages,QmlDebugger,V8Debugger,QmlInspector\".
Debugging has not been enabled.
Run Code Online (Sandbox Code Playgroud)
当我尝试使用相同的工具包在“日历”等演示项目中调试 QML 文件时,它确实工作并且断点被命中。
有任何想法吗?
我有以下功能:
class Foo;
template <typename T>
struct PyArray1D{
std::size_t size;
T *array;
};
extern "C" PyArray1D<Foo> SimulatePhotonEvents()
{
Foo * foo = new Foo();
return {1, foo}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不会使用 VS2019 编译(但是它使用 gcc 编译)并带有警告
C 链接函数不能返回 C++ 类
然而,当模板参数是双精度时它确实有效......我可以返回一个'PyArray1D',而VS不会抱怨。
所以我添加了一个新的结构:
struct FooArray {
std::size_t size;
Foo *data;
};
Run Code Online (Sandbox Code Playgroud)
并从 extern C 函数返回它。
extern "C" FooArray SimulatePhotonEvents()
{
Foo * foo = new Foo();
return {1, foo}
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这奏效了!我的问题是,为什么?
VS 不够聪明,可以看到 FooArray get 是从模板函数中创建的吗?还有其他更简单的方法来解决这个问题吗?
我已经使用pybind11创建了以下类:
py::class_<Raster>(m, "Raster")
.def(py::init<double*, std::size_t, std::size_t, std::size_t, double, double, double>());
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何在Python中调用此构造函数。我看到Python期望在double *位置使用浮点数,但我似乎无法调用它。
我已经尝试过,ctypes.data_as(ctypes.POINTER(ctypes.c_double))但这不起作用...
编辑:
我已经从@Sergei答案中提取了答案。
py::class_<Raster>(m, "Raster", py::buffer_protocol())
.def("__init__", [](Raster& raster, py::array_t<double> buffer, double spacingX, double spacingY, double spacingZ) {
py::buffer_info info = buffer.request();
new (&raster) Raster3D(static_cast<double*>(info.ptr), info.shape[0], info.shape[1], info.shape[2], spacingX, spacingY, spacingZ);
})
Run Code Online (Sandbox Code Playgroud) 如何在Qt小部件中检测滚动事件?
我想用它来滚动QWT图.我尝试过使用a QMouseEvent,但我只能找到移动和按下/释放鼠标的选项.
我在Qt中构建了一个包含两个按钮的应用程序:退出按钮和导入按钮.按下导入按钮时,屏幕上的滚动区域中会显示一个按钮列表(文件loggers.csv包含数据1; 2; 3; 4; 5;).
这一切都很好,但是当我按下退出按钮(当然应该关闭所有内容)时,应用程序没有正确停止(Qt的停止按钮仍处于活动状态,并且播放按钮不是).当我运行调试器并按下退出按钮时,它会给出一个错误:为RtlFreeHeap(0ADF0000,0028FE40)指定的地址无效.有谁能够帮我?
主要
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showFullScreen();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
Mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
#include "logger.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QPushButton exit_btn;
QPushButton import_btn;
private slots:
void createMenus();
void exit();
void import();
private:
int window_width;
int window_height;
int numLoggers;
int numSelected;
QVector<Logger*> loggers; …Run Code Online (Sandbox Code Playgroud) 我有一个Linux(3.12)系统(x86-64),其中有多个设备连接到PCI总线(PCI-e)。我想测量当前情况下的PCI总线负载,并在将另一台设备连接到总线上以查看两者之间的差异时再次测量,但是我不知道如何。有没有办法做到这一点?