小编cam*_*ino的帖子

如何在dbus-send中使用变体字典(`a {sv}`)

我dbus-send在使用时遇到了一些麻烦a{sv}

in_signature='a{ss}'使用以下命令行调用方法似乎工作:

dbus-send --dest="org.test.TestService" 
/org/test/TestService/object org.test.TestService.method1 dict:string:string:"a","1","b","2"
Run Code Online (Sandbox Code Playgroud)

现在我想为values(in_signature=a{sv})提供一个带变体类型的字典,

我该如何使用它dbus-send?

dbus

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

当z-index不工作时如何强制元素到顶部?

我正在编写一个chrome扩展,它使用注入来修改目标网页中的元素.我想在光标移动元素时显示消息气泡.但我遇到一个问题,有时消息泡沫被其他一些元素隐藏.我发现这是因为如果元素B位于元素A的顶部,则z-index将不起作用,元素A的子元素(消息气泡)永远不会高于元素B.

为了演示它,这是一个例子.尽管obj2的z-index是1000000,obj2总是会被obj3隐藏.

有什么解决方案吗?

.aaa{
    background-color:blue;
    width:100px;
    height:100px;
}
.ccc{
    background-color:red;
    width:80px;
    height:80px;
    z-index:1000000;
}
.bbb{
    background-color:green;
    position:relative;
    top:-50px;
    left:50px;
    width:100px;
    height:100px;
}
Run Code Online (Sandbox Code Playgroud)
<div>
    <section id=obj1 class="aaa">
    <article id=obj2 class="ccc">
    </article>
    </section>
</div>
<section id=obj3 class="bbb">
</section>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

css

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

调整容器大小时的奇怪行为

在调整向量大小时,它将调用构造函数然后销毁它.

struct CAT
{
    CAT(){cout<<"CAT()"<<endl;}
    CAT(const CAT& c){cout<<"CAT(const CAT& c)"<<endl;};
    ~CAT(){cout<<"~CAT()"<<endl;};
};
int main()
{
    vector<CAT> vc(6);
    cout<<"-----------------"<<endl;
    vc.resize(3);
    cout<<"-----------------"<<endl;

}
Run Code Online (Sandbox Code Playgroud)

输出:

$./m 
CAT()
CAT(const CAT& c)
CAT(const CAT& c)
CAT(const CAT& c)
CAT(const CAT& c)
CAT(const CAT& c)
CAT(const CAT& c)
~CAT()
-----------------
CAT()          //why resize will call constructor?
~CAT()
~CAT()
~CAT()
~CAT()
-----------------
~CAT()
~CAT()
~CAT()
Run Code Online (Sandbox Code Playgroud)

我使用的是ubuntu 13.10和gcc4.8

c++ vector

10
推荐指数
2
解决办法
178
查看次数

为什么不完整类型的智能指针数据成员和原始指针数据成员在父父进行破坏时会有不同的行为?

在以下代码中:

智能指针数据成员pImpl(类Impl)和原始指针pc(类CAT)都是不完整的数据类型,Widget.h中没有这两个类的定义

//widget.h

#ifndef W_H_
#define W_H_
#include <memory>

class Widget { 
    public:
        Widget();
        ~Widget() {    //
            delete pc; // I know I should put ~Widget to .cpp
                       // I just want to show the difference in behavior
                       // between raw pointer and smart pointer(both has incomplete type)
                       // when widget object destructs 
        }
    private:
        struct Impl; 
        std::shared_ptr<Impl> pImpl;  // use smart pointer
        struct CAT;
        CAT *pc;  //raw pointer
};
#endif
Run Code Online (Sandbox Code Playgroud)

//widget.cpp

#include "widget.h"

#include <string>
#include <vector>
#include <iostream> …
Run Code Online (Sandbox Code Playgroud)

c++ smart-pointers c++11

10
推荐指数
2
解决办法
2086
查看次数

在使用模板时得到"不能出现在常量表达式中"

template < int >  
  class CAT  
  {};  

  int main()  
  {  
     int i=10;  
     CAT<(const int)i> cat;  
     return 0; //here I got error: ‘i’ cannot appear in a constant-expression  
  }  
Run Code Online (Sandbox Code Playgroud)

甚至

   int i=10;  
   const int j=i;  
   CAT<j> cat; //this still can not work
Run Code Online (Sandbox Code Playgroud)

但我已将我转换为const int,为什么编译器仍报告错误?
我的平台是ubuntu,gcc版本4.4.3

谢谢,

==============

谢谢你的输入,但在某些情况下,我需要一个非const变量,

例如:

  //alloperations.h   
  enum OPERATIONS  
  {  
       GETPAGE_FROM_WEBSITE1,  
       GETPAGE_FROM_WEBSITE2,  
       ....  
  };  


  template< OPERATIONS op >  
  class CHandlerPara  
  {  
       static string parameters1;         
       static string parameters2;         
       ....  
       static void resultHandler();  
  };     


  //for different operations,we need a different …
Run Code Online (Sandbox Code Playgroud)

c++ parameters templates non-type

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

我们还需要"安置新"和"操作员新"吗?

似乎allocator执行与"placement new"和"operator new"相同的工作.它的界面更方便.

例如:

string *ps = static_cast<string *>(operator new(sizeof(string)));
new (ps) string("Hello");
cout<<*ps<<endl;
Run Code Online (Sandbox Code Playgroud)

可以改写成

allocator<string> as;
string *ps2 = as.allocate(1);
as.construct(ps2,"Hello");
cout<<*ps2<<endl;
Run Code Online (Sandbox Code Playgroud)

那么这意味着"贴牌新"和"操作员新"已经过时了?

c++

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

可以在linux中使用"man std :: find"吗?

我正在使用Ubuntu,并且已经安装了libstdc ++ 6-4.7-doc.

但它似乎man只适用于类,例如

$ man std::vector
$ man std::istream
Run Code Online (Sandbox Code Playgroud)

有效,但是

$ man std::find 
Run Code Online (Sandbox Code Playgroud)

没有用,有什么想法吗?

提前致谢!

改性:

安装libstdc ++后??? - doc

我们可以使用file:///usr/share/doc/gcc-4.7-base/libstdc++/html/index.html来访问文档.

c++ stl manpage

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

是否可以直接将网页呈现给python中的图像?

现在我使用selenium将网页保存为图像.

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("some url")
browser.save_screenshot(img)
browser.quit()
Run Code Online (Sandbox Code Playgroud)

但每次弹出窗口都会出现问题.

有没有办法可以直接将图像渲染到图像?

python selenium-webdriver

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

按下颤动后如何立即更改图标颜色?

我想在按下图标后更改它的颜色,但似乎以下代码不起作用。

  void actionClickRow(String key) {
    Navigator.of(context).push(
      new MaterialPageRoute(builder: (context) {
        return new Scaffold(
            appBar: new AppBar(
              title: new Text(key),
              actions: <Widget>[
                new IconButton(
                  icon: new Icon(
                    Icons.favorite, 
                    color: isSaved(key)  ? Colors.red : null,  //<--- if key is already saved, then set it to red
                    ), 
                  onPressed: ()
                  {
                    setState(() //<--whenever icon is pressed, force redraw the widget
                    {
                      pressFavorite(key);
                    });                    
                  }
                ),
              ],
            ),
            backgroundColor: Colors.teal,
            body: _showContent(key));
      }),
    );
  }


 void pressFavorite(String key)
  {
    if (isSaved(key))
      saved_.remove(key);
    else
      saved_.add(key); …
Run Code Online (Sandbox Code Playgroud)

flutter

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

为什么我们需要std :: promise和std :: future?

我想知道为什么我们需要std :: promise和std :: future?为什么c ++ 11标准将get和set_value分成两个独立的类std :: future和std :: promise?在这篇文章的答案中,它提到:

将它分成这两个独立的"接口"的原因是隐藏"消费者/读者"的"写入/设置"功能.

我不明白隐藏在这里的好处.但如果我们只有一个班级"未来",这不是更简单吗?例如:promise.set_value可以替换为future.set_value.

c++ c++11

8
推荐指数
2
解决办法
3220
查看次数