小编avi*_*iit的帖子

capset因指向struct而失败

我有两个代码示例:
第一,正确运行:

#include <sys/capability.h>
#include <unistd.h>
#include <cstdio>

int main()
{
    __user_cap_header_struct *hdr = new __user_cap_header_struct;
    __user_cap_data_struct *data = new __user_cap_data_struct;
    hdr->pid = getpid();
    hdr->version = _LINUX_CAPABILITY_VERSION;
    data->effective &= ~CAP_TO_MASK(CAP_IPC_LOCK);
    data->permitted &= ~CAP_TO_MASK(CAP_IPC_LOCK);
    data->inheritable = 0;
    if (capset(hdr, data) < 0)
        printf("capset failed: %m");

    return 0
}
Run Code Online (Sandbox Code Playgroud)

第二,fail: Operation not permitted:

#include <sys/capability.h>
#include <unistd.h>
#include <cstdio>

int main()
{
    struct __user_cap_header_struct hdr;
    hdr.pid = getpid();
    hdr.version = _LINUX_CAPABILITY_VERSION;
    struct __user_cap_data_struct data;   
    data.effective &= ~CAP_TO_MASK(CAP_IPC_LOCK);    
    data.permitted &= ~CAP_TO_MASK(CAP_IPC_LOCK); …
Run Code Online (Sandbox Code Playgroud)

c struct linux-capabilities

1
推荐指数
1
解决办法
1284
查看次数

静态QApplication变量使Mac在退出时报告崩溃

以下代码在Windows或Linux(Debian)上运行良好,但在Mac上报告退出时崩溃:

int main(int argc, char *argv[]) {
  static QApplication app(argc, argv);
  QPushButton w; w.show();
  return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

我需要这个app变量必须是静态的.我解决这个问题:

static QApplication& app = *new QApplication(argc, argv);
Run Code Online (Sandbox Code Playgroud)

但我不喜欢这种风格.你有什么建议吗?非常感谢你!

更新:添加有关报告的图像(并更新我正在使用的代码示例): 在此输入图像描述

c++ macos qt static-variables

1
推荐指数
1
解决办法
205
查看次数

如何在同级 QVideoWidget 之上创建透明 QWidget?

我想在全屏上添加一些控件和信息QVideoWidget。因此,我创建一个QMainWindowui,然后将中央小部件提升为QVideoWidget在此输入图像描述

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>VideoScreen</class>
 <widget class="QMainWindow" name="VideoScreen">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <property name="styleSheet">
   <string notr="true"/>
  </property>
  <widget class="QVideoWidget" name="videoScreen">
   <property name="styleSheet">
    <string notr="true"/>
   </property>
  </widget>
 </widget>
 <customwidgets>
  <customwidget>
   <class>QVideoWidget</class>
   <extends>QWidget</extends>
   <header>QVideoWidget</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>
Run Code Online (Sandbox Code Playgroud)

ControlBoards用户界面: 在此输入图像描述

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ControlBoard</class>
 <widget class="QWidget" name="ControlBoard">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1044</width>
    <height>520</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property> …
Run Code Online (Sandbox Code Playgroud)

qt transparent qt5 qvideowidget

1
推荐指数
1
解决办法
2357
查看次数

paint函数无限地重新循环

我更新了diagramcene示例以绘制窄线的法线.我在Arrow::paint功能中添加了这一行:

painter->drawLine(line());   
painter->drawLine(line().normalVector()); // this line was added
//...
//scene()->update(); //add this line make this paint function reloop infinitely
Run Code Online (Sandbox Code Playgroud)

没有update,正常线没有显示,如果我移动项目,它可以显示但不正确.有了update,所有都是正确的绘画,但paint功能是无限的reloop.我无法解释原因,请帮帮我!

// - 编辑:我添加了原始Arrow::paint函数的代码:

void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
          QWidget *)
{
    if (myStartItem->collidesWithItem(myEndItem))
        return;

    QPen myPen = pen();
    myPen.setColor(myColor);
    qreal arrowSize = 20;
    painter->setPen(myPen);
    painter->setBrush(myColor);

    QLineF centerLine(myStartItem->pos(), myEndItem->pos());
    QPolygonF endPolygon = myEndItem->polygon();
    QPointF p1 = endPolygon.first() + myEndItem->pos();
    QPointF p2;
    QPointF intersectPoint;
    QLineF polyLine;
    for (int i …
Run Code Online (Sandbox Code Playgroud)

c++ qt qpainter qgraphicsitem

0
推荐指数
1
解决办法
107
查看次数