问题列表 - 第45170页

使用XElement查询命名空间中的节点

我试图从一个看起来像这样的csproj文件中提取一个节点,但是无法让它工作 - 大概是因为名称空间声明.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
      <PropertyGroup>
          <RegisterForComInterop>true</RegisterForComInterop>
Run Code Online (Sandbox Code Playgroud)

这失败了:

XDocument cpo = XDocument.Load(file);
XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/200");
IEnumerable<XElement> list3 = cpo.XPathSelectElements("//x:RegisterForComInterop[.='true']", nsm);
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

谢谢.

c# xelement namespaces

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

带有QCompleter的QLineEdit不会显示带有空文本字段的QCompleter弹出菜单

我有一个QLineEdit,与QCompleter它相关的对象.如果用户输入至少一个字符,则显示来自该字符的弹出菜单QCompleter,但是当用户删除最后一个字符(从而使该字段为空)时,弹出窗口消失.即使QLineEdit文字是空的,有没有办法让它显示出来?

c++ qt qt4

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

确定文件是否为空(php)的最佳方法是什么?

我在我的模板中包含了custom.css文件,以允许网站所有者添加自己的css规则.但是,当我发送文件时,它是空的,如果他们没有添加任何规则,就没有意义加载它.

确定它是否空的最佳方法是什么?

if ( 0 == filesize( $file_path ) )
{
    // file is empty
}

// OR:

if ( '' == file_get_contents( $file_path ) )
{
    // file is empty
} 
Run Code Online (Sandbox Code Playgroud)

php

38
推荐指数
4
解决办法
6万
查看次数

如何以更易读的方式混洗我的数组或字符串列表?

想象一下,您希望拥有一个非常易读且易于编辑的项目列表,仅以逗号分隔,然后从该列表中回显3个随机项目.数组或字符串无关紧要.现在,我得到了以下工作(感谢webbiedave!)

$fruits = array('Mango', 'Banana', 'Cucumber', 'Pear', 'Peach', 'Coconut');

$keys = array_rand($fruits, 3);   // get 3 random keys from your array
foreach ($keys as $key) {         // cycle through the keys to get the values
    echo $fruits[$key] . "<br/>";
}
Run Code Online (Sandbox Code Playgroud)

输出:

Coconut
Pear
Banana
Run Code Online (Sandbox Code Playgroud)

这里唯一未解决的是列表不是我想要的那样可读:就个人而言,我更喜欢输入列表没有引号,例如Mango相反'Mango',意思是最好像这样:

(Mango, Banana, Cucumber, Pear, Peach, Suthern Melon, Coconut)

这很容易吗?非常感谢您的投入.

php arrays string random shuffle

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

清除Qt中的布局

我正在Qt中创建一个应用程序,允许用户在QGraphicsView中拖动各种"模块".每当选择其中一个模块时,它会发出一个信号,然后由"ConfigurationWidget"拾取,这是一个侧面板,应该显示所选模块的所有相关参数:

class ConfigurationWidget : public QWidget
{
  Q_OBJECT

  public:
    ConfigurationWidget(QWidget *parent) : QWidget(parent) {}  

  public slots:
    void moduleSelected(Module* m)
    {
      if(layout())
      { 
        while (itsLayout->count()>0) 
        { 
          delete itsLayout->takeAt(0); 
        }
      }
      delete layout();

      itsLayout = new QFormLayout(this);
      itsLayout->addRow(QString(tr("Type:")),     new QLabel(m->name()));
      itsLayout->addRow(QString(tr("Instance:")), new QLabel(m->instanceID()));
      // ... Display a whole bunch of other fields that depends on the module
    }
};
Run Code Online (Sandbox Code Playgroud)

问题是当选择模块时,ConfigurationWidget实际上永远不会被清除.新字段只是绘制在旧字段上.我尝试过hide()和show(),invalidate(),update()等各种组合无济于事.

制作可以动态改变其字段的小部件的正确方法是什么?

c++ qt qt4

12
推荐指数
3
解决办法
2万
查看次数

如何以编程方式获取iOS的字母数字版本字符串

我一直在使用漂亮的PLCrashReport框架从我的用户的iOS设备向我的服务器发送崩溃报告.

但是,为了表示崩溃报告,symbolicatecrash实用程序请求与iPhone OS版本号一起,我有ipsw的字母数字版本,格式为:

OS Version:      iPhone OS 4.0.1 (8A293)
Run Code Online (Sandbox Code Playgroud)

我知道我可以获得iOS的数字版本[[UIDevice currentDevice] systemVersion],但我怎么能得到另一个呢?

我无法找到方法,而且我已经搜遍了我能想到的每一个地方.

objective-c ios

19
推荐指数
2
解决办法
1万
查看次数

RegEx拒绝未转义的HTML字符

我想限制在特定输入字段中使用未转义的&符号.我无法使用RegEx来杀死"&"的使用,除非后面跟"amp;"......或者只是限制使用"&"(注意空格).

我尝试在这个帖子中调整答案,但无济于事.谢谢.

(FWIW,这是我做的RegEx,以确保文件名字段不包含重写的字符.并以.mp3结尾.它工作正常,但它看起来效率高吗?)

^[^&,<,>,:,",/,\\,|,?,\*]+(\.mp3|\.MP3|\.Mp3|\.mP3)$
Run Code Online (Sandbox Code Playgroud)

html regex xml escaping ampersand

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

如何在Solr中指定日期构面查询?

当我对Solr进行查询时,我得到了这些facet_counts:

'facet_counts' => {
    'facet_dates' => {
        'photo_added' => {
            '2009-12-28T18:00:00Z' => 396386,
            '2010-05-28T18:00:00Z' => 415370,
            'gap' => '+1MONTH',
            'end' => '2011-02-28T18:00:00Z',
        },
    },
},
Run Code Online (Sandbox Code Playgroud)

但是,当我向查询中添加这些参数中的任何一个q=*:*:

fq=photo_added:2009-12-28T18:00:00Z
fq=photo_added:2009-12-28T18%3A00%3A00Z
Run Code Online (Sandbox Code Playgroud)

我收到这个作为回应:

HTTP ERROR 400: Invalid Date String:'2009-12-28T18'
Run Code Online (Sandbox Code Playgroud)

当我向查询中添加这些参数中的任何一个时:q=*:*

fq=photo_added:"2009-12-28T18:00:00Z"
fq=photo_added:"2009-12-28T18%3A00%3A00Z"
fq%3Dphoto_added%3A%222009-12-28T18%3A00%3A00Z%22
fq=photo_added%3A"2009-12-28T18%3A00%3A00Z"
Run Code Online (Sandbox Code Playgroud)

我在回复中收到了这个:

<result name="response" numFound="0" start="0"/>
Run Code Online (Sandbox Code Playgroud)

但是当我fq=对我的查询没有约束时,我得到了numFound="8001000",所以这个fq=约束肯定有问题.

如何进行有效的日期构面查询?

solr

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

派生自std :: exception

我想从std :: exception派生,以便将特定信息添加到我的日志文件中,但我无法想象如何从std :: exception访问.what().

此外,我知道在我的异常处理程序中创建一个字符串是不安全的,但我不是这个主题的专家,那么什么是更安全的替代品?

struct Exception : public std::exception, private boost::noncopyable
{
    public:
        Exception(std::string msg)
            : message(msg)
        {}
        ~Exception()
        {}

        virtual const char* what() const throw 
        {
            std::string what = message + // and now what? base.what()
            LOG(what); // write to log file
            return what.c_str();
        }

    private:
        std::string message;
};
Run Code Online (Sandbox Code Playgroud)

编辑:我真的以错误的方式问我的问题.我对安全性很感兴趣,我只是觉得拥有更多的日志数据会很好.我错了.

现在,我并没有因为消息字符串抛出bad_alloc而变得如此偏执以防万一之前有一个bad_alloc,我宁愿有一个简洁的消息.据说我改写了一些东西:

struct Exception : public std::exception
{
    public:
        Exception(std::string msg)
            : message(msg)
        {}
        ~Exception()
        {}

        virtual const char* what() const throw 
        {
            LOG(what); // write to log …
Run Code Online (Sandbox Code Playgroud)

c++ exception-handling

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

从初始和结果2D矩阵计算2D变换矩阵

在编程方面我绝不自称是天才,而我当前的问题让我感到难过.

我发现这个问题试图仅使用似乎至少部分回答我的问题的图像来导出2D变换矩阵,但应该显示解决方案的图像不再可用:S

我正在使用C#而不使用WPF,因为我的输入或输出都不需要以图形方式显示.

在我的程序中,我有2个四边形,让我们称它们为输入和输出四边形.

输入四边形从左下方顺时针方向具有(2,1),(2,3),(4,4),(3,1)的共同点.

输出四边形可以有任何合并,并将从左下方顺时针再次按顺序列出.

给定这8个坐标对,是否可以计算出可以应用于任何单个坐标对的变换矩阵?

我对Matrices不太热,但我愿意学习指向正确的方向.

非常感谢

玩笑

c#

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

标签 统计

c++ ×3

c# ×2

php ×2

qt ×2

qt4 ×2

ampersand ×1

arrays ×1

escaping ×1

exception-handling ×1

html ×1

ios ×1

namespaces ×1

objective-c ×1

random ×1

regex ×1

shuffle ×1

solr ×1

string ×1

xelement ×1

xml ×1