问题列表 - 第175249页

模板函数实现中的条件取决于类型是否为指针

所以我有这个模板功能.它应该在一个更复杂的结构中设置一个变量AbstractEvent:

template< typename T >

void AbstractEvent::setVar( QString varName, T value) 
{
    if (std::is_pointer<T>::value)
    {
        void * castValue = static_cast<void*>(value);
        if (castValue)
        {
            //do sth with castValue
        }

     }
     else
     {
        //do something with value
     }
}
Run Code Online (Sandbox Code Playgroud)

使用此模板函数,我想将变量"value"存储在QVariant中,然后将QVariant存储在某处.

如果"value"是指针,我想将它作为void*存储在QVariant中.对于其他任何我想存储真实类型的东西.

我尝试使用C++ trait std :: is_pointer :: value来检查value是否为指针.

这段代码编译得很好,但是当我尝试使用它时,例如:

int intValue = 0;
setVar<int>("aVar",intValue);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error C2440: 'static_cast' : unable to convert from 'int' to 'void *'
Run Code Online (Sandbox Code Playgroud)

我认为编译器很困惑,因为它正在检查这一行:

    void * castValue = static_cast<void*>(value);
Run Code Online (Sandbox Code Playgroud)

当值不是指针时,这当然没有意义.这就是我的if语句

     if (std::is_pointer<T>::value)
Run Code Online (Sandbox Code Playgroud)

应该避免,但是,即使在运行时,这段代码的值作为int将永远不会被执行,在编译时它会混淆编译器......是否有解决这类问题的方法?

c++ templates pointers

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

iOS崩溃:[__ NSArrayM allKeys]:无法识别的选择器发送到实例0x178754d0

用户遇到此崩溃[__NSArrayM allKeys]: unrecognized selector sent to instance 0x178754d0 这是发生崩溃的地方.

NSArray *sortedArray = [[array allKeys] sortedArrayUsingFunction:sort context:nil];
Run Code Online (Sandbox Code Playgroud)

我不确定这是怎么发生的.任何有关如何防止这种情况的提示或建议将不胜感激.

编辑:这是我的数组,我应该更改变量名.

id array = [parse objectWithString:answer];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

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

mysql中的订单字段的默认值

在给定的表中,我有一个field(field_order),用于定义显示表行的自定义顺序.插入新记录时,我想设置该特定字段,其中包含该表中的行数加1

因此,如果表有3行,则在插入新行时,默认值field_order应为4.

设定该值的最佳方法是什么?

insert语句中有一个简单的select count?

CURRENT_TIMESTAMP对于TIMESTAMP返回该值的数据类型是否有常量?

编辑:这背后的原因是能够按该特定字段对表进行排序; 并且该字段将由客户端的用户使用jQuery的可排序操作

mysql

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

我们可以为ASP.NET MVC 5中的角色个性化会话超时

我们的想法是为ASP.NET MVC 5和ASP.NET Identity中的不同用户角色设置不同的会话超时值.

有可能吗?

asp.net-mvc roles session-timeout asp.net-mvc-5 asp.net-identity

6
推荐指数
2
解决办法
2883
查看次数

Select2 - Ajax搜索 - 记住最后的结果

我正在使用Select2 3.5.1.有了这个插件,我可以成功加载远程数据.但是我今天在这里提出一个问题来改进这种搜索.以下是逐步了解我想要做的事情:

  1. 设置带有远程数据加载的Select2(使用ajax).
  2. 单击Select2输入并搜索某些内容.
  3. 将显示加载,几秒钟后您将看到结果列表.
  4. 单击列出的结果之一 - 结果框将消失.
  5. 如果再次单击搜索框,列表将为空,您需要再次键入一些新文本以获得结果列表.

是否有可能当我们再次点击搜索框时,先前搜索过的结果列表重新出现而没有任何ajax调用?然后,如果用户删除字符或更改其搜索条件,则它将再次触发ajax搜索.

如果有可能,我们将如何编码呢?

我希望我的问题很清楚,如果您有任何问题,请告诉我.谢谢.

这是一个非常简单的代码,我们进行搜索,返回结果列表.它并不真正搜索,但它会在您输入内容时返回一个列表.我不知道如何使用其中一个响应中提到的initSelection.

<html>
<head>
    <title>
        Test page for ajax cache
    </title>
    <script type='text/javascript' src='../../resources/javascript/jquery/jquery-1.9.1.min.js'></script>
    <link type='text/css' href='../../resources/javascript/select2/select2.css' rel='stylesheet' />
    <script type='text/javascript' src='../../resources/javascript/select2/select2.js'></script>

    <script>
    $(document).ready(function(){
        $('#select').select2({
            ajax: {
                type: 'POST',
                url: 'ajax.php',
                dataType: 'json',
                data: function(term, page){
                    return {
                        autoc: 'country',
                        term: term
                    }
                },
                results: function(data, page){
                    console.log(data);

                    return( {results: data.results} );
                }
            },
            placeholder: 'Search something',
            minimumInputLength: 3,
            width: '333'
        });
    });
    </script>
</head>

<body>
    <input type='text' name='inputdata' …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery jquery-select2

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

内联文本字段和输入不对齐

我正在实现内联表单.用户可以搜索现有客户或添加新客户.

<div id="CustomerInfo">
    <div class="display-field roomy">
        <div id="customerInfoContainer">
            <div class="addCustomerControlsContainer">
                <span class="twitter-typeahead" style="position: relative; display: inline-block;"><input type="text" class="autocompleteinput tt-query" placeholder="Type to search" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: rgba(0, 0, 0, 0);"></span>
                <input class="add-new-customer" title="Add New Customer" type="button" value="+">
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我的两个元素不排队?

http://jsfiddle.net/gq2279j2/4/

css

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

在 HTML / .format() 中使用 Python 变量

我很难让“标记”出现。我不知道如何.format()正确使用来显示字符串内的标记。

变量是否需要位于字符串中的特定位置?第一次尝试掌握这一点。抱歉,如果我问的是基本问题。

继续得到:""".format(marker) KeyError: 'font-family'。不确定问题出在哪里。

marker = "AUniqueMarker"    


# Create the body of the message (a plain-text and an HTML version).
text = "This is a test message.\nText and html."
html = """\
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 15">
<meta name=Originator content="Microsoft Word 15">
<link rel=File-List href="Law_files/filelist.xml">
<!--[if gte mso 9]><xml>

# (...)

-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style …
Run Code Online (Sandbox Code Playgroud)

html python variables string.format

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

使用Android支持库和Maven的NoClassDefFoundError

使用Maven Android插件的最新版本4.0.0-rc.1,构建中似乎缺少一些类.当我启动应用程序时,我得到了一个例外(启动应用程序的两种可能方式):

  • java.lang.NoClassDefFoundError:android.support.v4.app.TaskStackBuilderHoneycomb
  • java.lang.NoClassDefFoundError:android.support.v4.widget.EdgeEffectCompatIcs

两个缺少的类都在support-v4-21.0.0.aar/libs/internal_impl-21.0.0.jar中.

我的依赖定义:

    <dependency>
        <groupId>com.android.support</groupId>
        <artifactId>support-v4</artifactId>
        <version>21.0.0</version>
        <type>aar</type>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

这是一些配置错误吗?Android Maven插件中的一个错误?

android maven android-support-library android-maven-plugin

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

iOS检查UINavigationController中是否显示Back Button

在iOS项目中,我需要检查当前是否显示后退按钮.我已经尝试过在SO上提供的一些解决方案,但它们都没有为我工作.目前我正在使用此代码

NSArray *stack = navigationController.viewControllers;
int i = stack.count-2;

if (i>=0)
{
    UIViewController *backVC = (UIViewController*)[stack objectAtIndex:i];
    if (backVC.navigationItem.backBarButtonItem != nil) {
        NSLog(@"Back button is displayed!");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是日志中没有任何内容.如果我正确理解苹果指南,我正在寻找位于堆栈索引n-2的ViewController,ViewController应该保持一个后退按钮.

我在-navigationController中使用此代码:willShowViewController:animated:

uinavigationcontroller ios

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

如何为RecyclerView创建上下文菜单

如何实现上下文菜单RecyclerView?显然调用registerForContextMenu(recyclerView)不起作用.我是从片段中调用它的.有没有人有成功实现这个?

android contextmenu android-recyclerview

89
推荐指数
8
解决办法
7万
查看次数