小编Nic*_*ton的帖子

How do I read binary C++ protobuf data using Python protobuf?

The Python version of Google protobuf gives us only:

SerializeAsString()
Run Code Online (Sandbox Code Playgroud)

Where as the C++ version gives us both:

SerializeToArray(...)
SerializeAsString()
Run Code Online (Sandbox Code Playgroud)

We're writing to our C++ file in binary format, and we'd like to keep it this way. That said, is there a way of reading the binary data into Python and parsing it as if it were a string?

Is this the correct way of doing it?

binary = get_binary_data()
binary_size = get_binary_size()

string = None
for i in range(len(binary_size)): …
Run Code Online (Sandbox Code Playgroud)

c++ python protocol-buffers

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

如何使用Qt安装Windows服务?

我们有一个使用WinAPI的现有C++应用程序(我们称之为"SvcApp").我们有另一个名为"MgrApp"的C++ WinAPI应用程序,它安装并启动"SvcApp"作为Windows服务.

但是,我们想用Qt应用程序替换"SvcApp".我可能会被误导,但似乎无法使用<windows.h>Qt应用程序,因此我似乎无法复制并粘贴"MgrApp"中的所有现有代码......或者我可以吗?

总而言之,我们需要从Qt应用程序中执行以下操作:

  • 启动/停止Windows服务
  • 安装/卸载Windows服务

qt windows-services

5
推荐指数
2
解决办法
4618
查看次数

如何在Django/Python Web应用程序中使用Trac wiki格式?

我有一个Python Web应用程序(特别是Django).我正在读取Trac数据库中的一些数据(其中描述使用wiki格式)并将其显示为HTML.我考虑过markdown模块,但意识到Trac wiki格式化和markdown真的很不一样.是否有Django的模块,或支持Trac使用的wiki格式的Python包?

更新:

我的投票结束时看起来有点仓促 - 而另一张票看起来很相似,我的问题更多的是与Trac wiki格式化有关.感谢petantik的链接!

类似的问题: 我在哪里可以获得我的django应用程序的wiki格式化小部件?

python django trac

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

我应该使用接口或工厂(和接口)进行跨平台实现吗?

例A:

// pseudo code
interface IFoo {
    void bar();
}

class FooPlatformA : IFoo {
    void bar() { /* ... */ }
}

class FooPlatformB : IFoo {
    void bar() { /* ... */ }
}

class Foo : IFoo {
    IFoo m_foo;
    public Foo() {
        if (detectPlatformA()} {
            m_foo = new FooPlatformA();
        } else {
            m_foo = new FooPlatformB();
        }
    }

    // wrapper function - downside is we'd have to create one 
    // of these for each function, which …
Run Code Online (Sandbox Code Playgroud)

factory cross-platform interface

5
推荐指数
2
解决办法
726
查看次数

是否可以将一个MetaPost文件包含在另一个中?

我有两个metapost文件:

% test1.mp
beginfig(1):

% foobar code

% code specific to test1

endfig;
end;
Run Code Online (Sandbox Code Playgroud)
% test2.mp
beginfig(1):

% foobar code    

% code specific to test2

endfig;
end;
Run Code Online (Sandbox Code Playgroud)

作为程序员,我自然不喜欢重复.有没有办法将"foobar代码"移动到foobar.mp文件中,然后在test1.mp和test2.mp中包含此文件?例如...

% test1.mp
beginfig(1):

% for illustration...
Include.foobar("foobar.mp");

% code specific to test2

endfig;
end;
Run Code Online (Sandbox Code Playgroud)

metapost

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

为什么我不能在SQL Server 2008中注册System.Web?

运行此命令:

CREATE ASSEMBLY 
[System.Web] from
'C:\Windows\Microsoft.NET\Framework\v2.0.50727\system.web.dll'
with permission_set = UNSAFE
Run Code Online (Sandbox Code Playgroud)

给我这个错误:

消息10300,级别16,状态2,第1行

程序集"System.Web"引用程序集"system.web,version = 2.0.0.0,culture = neutral,publickeytoken = b03f5f7f11d50a3a.",它在当前数据库中不存在.SQL Server尝试从引用程序集来自的相同位置定位并自动加载引用的程序集,但该操作失败(原因:版本,区域性或公钥不匹配).请将引用的程序集加载到当前数据库中,然后重试您的请求.

......这听起来有点傻.看起来SQL Server认为System.Web程序集正在引用它自己.我怎样才能解决这个问题?

sql-server sqlclr

5
推荐指数
2
解决办法
4276
查看次数

如何从Linux中的图形输入板手写笔读取压力值?

我正在尝试在Linux上为Synergy添加压力敏感性支持.我认为第一步应该是检测服务器端的压力值.当调用XNextEvent时,手写笔移动作为MotionNotify事件进入.但是,当使用触控笔时,此线不输出压力值:

   case MotionNotify:
           XDeviceMotionEvent* motionEvent = reinterpret_cast<XDeviceMotionEvent*>(xevent);
           LOG((CLOG_INFO "tablet event: pressure=%d", motionEvent->axis_data[2]));
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我猜测我可能没有"订阅"这样的信息,所以按照我在网上找到的一些例子,我试图打开Wacom设备:

   void
   CXWindowsScreen::openWacom()
   {
           // init tablet (e.g. wacom)
           int deviceCount;
           XDeviceInfo* deviceInfo = XListInputDevices(m_display, &deviceCount);
           for (int i = 0; i < deviceCount; ++i) {

                   if (CString(deviceInfo[i].name).find("stylus") != CString::npos) {

                           LOG((CLOG_INFO "tablet device: name='%s', id=%d",
                                           deviceInfo[i].name, deviceInfo[i].id));

                           XDevice* tabletStylusDevice = XOpenDevice(m_display, deviceInfo[i].id);
                           if (tabletStylusDevice == NULL) {
                                   LOG((CLOG_ERR "failed to open tablet device"));
                                   return;
                           }

                           XEventClass eventClass;
                           DeviceMotionNotify(tabletStylusDevice, m_tabletMotionEvent, eventClass);
                           XSelectExtensionEvent(m_display, m_window, &eventClass, 1);

                           LOG((CLOG_INFO "tablet motion …
Run Code Online (Sandbox Code Playgroud)

c++ linux x11 wacom

5
推荐指数
0
解决办法
1874
查看次数

在C++中共享库主头文件的最佳实践是什么?

当我创建共享库时,我在库源的根目录中有一个头文件(但没有文件扩展名),名称与库相同.

例如,如果我的库名为libirock.so,那么我在项目根目录中有一个名为irock的文件.此文件将包含库中所有最重要的标头,因此在实现库时,您只需使用此包含行:

#include <irock> // Instead of <irock.h>
Run Code Online (Sandbox Code Playgroud)

当我看到类似于的编译器警告时,我明白了这个想法:

#include <string.h> is obsolete, use #include <string> instead
Run Code Online (Sandbox Code Playgroud)

两个问题:

  1. 使用irock而不是irock.h最佳实践?
  2. 使用单个头文件而不是许多头是正确的吗?

行动方针

谢谢你的回答!从答案中,我决定:

  1. 将使用<irock.h>而不是<irock>.
  2. 我将继续使用"主要"头文件.

c++ header shared-libraries

4
推荐指数
3
解决办法
1233
查看次数

如何在OpenGL中将像素作为纹理绘制到多边形?

在C++ OpenGL中,我想手动绘制每个像素(作为我假设的纹理)到一个简单的方形基元,或者实际上形成一个正方形的2个多边形.

我不知道从哪里开始,或者寻找什么短语.我在寻找纹理贴图还是创建纹理?大多数示例都是从文件加载,但我不想这样做.

我试过阅读我的OpenGL编程指南书,但它只是一个迷宫,因为我对OpenGL很新.请帮忙.

c++ opengl textures

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

如何从它所在的类中访问C++下标运算符?

其中,ClassA有一个运算符,返回ClassB:

class ClassA
{
public:
    ClassA();
    ClassB &operator[](int index);
}
Run Code Online (Sandbox Code Playgroud)

如果我想从ClassA的构造函数中访问所述运算符,如下所示:

ClassA::ClassA()
{
    // How do I access the [] operator?
}
Run Code Online (Sandbox Code Playgroud)

目前,作为一种解决方法,我只是使用[]运算符调用的名为GetAtIndex(int index)的方法,构造函数也是如此.

如果我可以像C#一样访问它,那将是很好的:

// Note: This is C#
class ClassA
{
   ClassB this[int index]
   {
       get { /* ... */ }
       set { /* ... */ }
   }

   void ClassA()
   {
       this[0] = new ClassB();
   }
}
Run Code Online (Sandbox Code Playgroud)

注意:我正在使用g ++

c# c++ subscript-operator

4
推荐指数
2
解决办法
1202
查看次数